top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to recover deleted files using python?

+1 vote
2,798 views

I was trying to program with txt files, and tried to move the txt file to a new directory. By mistake I have deleted some of my files. How do I recover my lost files using python or any other method?

posted Dec 26, 2013 by Jagan Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

I'm afraid Python can't really help you there; you have to go to your OS and file system now. Do as little as you possibly can on that disk and you might be able to recover the contents. If you're lucky, your file system won't have reused those parts of the disk, so everything'll be intact... if you're REALLY lucky, you might even be able to find the bits you want without searching the whole disk. But it depends now on your OS and FS, not on Python.

This is why we make backups of all important files. I like to use source control (git for me, or you could use Mercurial or another one with the same result), which makes backing up an inherent part of all work. But everyone has those critical files that they didn't know weren't backed up... :(

answer Dec 26, 2013 by Bob Wise
+1 vote

if you have net app in your Linux system you can recover files from 2 day back Otherwise its all dependent on your OS how you can recover your deleted file, not python .

answer Jan 11, 2014 by Amit Kumar Pandey
Similar Questions
+3 votes

Does someone know where the files after a "git rm" go? Some of my files where deleted by git, of course I have no copy, I tried several file recovery utilities, but so far none of them see the deleting files.

I am running Windows 7; git 1.9.4; gitextension 2.48.03

Full story:
One week ago I created a new repository from an old CVS server. I checked it out from scratch (clone it), into CLONE, and copy the .git folder into a folder, MyFolder, containing some changes that were not pushed under CVS. So far everything ran fine, I could pushed the new changes.

However, MyFolder contained also a a folder called Perso with some files I did not want to push. Therefore I added Perso/* into .gitignore. Then the folder Perso disappeared as potential commit. So far so good. Then I don't really remember what I've done, maybe clean some branches? but yesterday I remarked that Perso/ was no more on the disk.

Currently there is no stash, no other branches. I tried a menu (under GitExtensions) "Repository/Git Maintenance/Recover lost objects" with option "print out objects that exists but that aren't readable from any of the reference nodes"... without success. I suppose git removed my files when switching the branch? Hence my question, is there a change I could get these files back? I am afraid they are lost... what a silly situation.

+1 vote

I have about 500 search queries, and about 52000 files in which I have to find all matches for each of the 500 queries.

How should I approach this? Seems like the straightforward way to do it would be to loop through each of the files and go line by line comparing all the terms to the query, but this seems like it would take too long.

Can someone give me a suggestion as to how to minimize the search time?

+3 votes

I am trying to count the number of files in a folder with python script but not getting the appropriate script. In which I can change the path and can find out the count of other folder files.

It doesn't matter for me how long the script is but need the clear script and it would be better if you can explain it also.

+2 votes

I want to take the file, "desktop/test.txt" and write it to "desktop/newfolder/test.txt". I tried the below script, and it gave me: "IOError: [Errno 2] No such file or directory: 'desktop/%s.txt'". Any suggestions would be great.

def firstdev(file):
 in_file = open("desktop/%s.txt") % file
 indata = in_file.read()
 out_file = open("desktop/newfolder/%s.txt", 'w') % file
 out_file.write(indata)
 out_file.close()
 in_file.close()

firstdev("test")
...