Recovering deleted files

G

George Tang

I am new to python and was trying to program with txt files, and tried to move the txt file to a new directory. i did not read very carefully about what shutil.move(src, dst) does and it deleted some of my files. How do i recover my lost files. plz help!
 
C

Chris Angelico

I am new to python and was trying to program with txt files, and tried to move the txt file to a new directory. i did not read very carefully about what shutil.move(src, dst) does and it deleted some of my files. How do i recover my lost files. plz help!

Ouch. 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... :(

ChrisA
 
D

Dennis Lee Bieber

I am new to python and was trying to program with txt files, and tried to move the txt file to a new directory. i did not read very carefully about what shutil.move(src, dst) does and it deleted some of my files. How do i recover my lost files. plz help!

If I read the documents properly, shutil.move() does not just blindly
delete files (it does a copy/delete if crossing file systems, otherwise it
just does a rename).

So where did to instruct it to put what had been the source
file/directory? Look in that destination location...
 
S

Steven D'Aprano

Dennis said:
If I read the documents properly, shutil.move() does not just blindly
delete files (it does a copy/delete if crossing file systems, otherwise it
just does a rename).

What difference does that make? Regardless of whether you do a copy/delete
or rename, whatever file was overridden by the move is still overridden.
 
R

Rick Johnson

I am new to python and was trying to program with txt
files, and tried to move the txt file to a new directory.
i did not read very carefully about what shutil.move(src,
dst) does and it deleted some of my files. How do i
recover my lost files. plz help!

Well George that's unfortunate.

I hate to say "i told you so", but i've been preaching the
importance of testing code that manipulates files for many
years. If only you had run the code a few times and MERELY
printed the src and dst paths to stdout you MIGHT could have
saved yourself a tough lesson.

But all may not be lost.

If you want to post the relevant bits of the source code we
may find a solution for you. Maybe your path munging was
clumsy and you moved them somewhere unexpected... who
knows???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top