23
That moment my first Python script deleted my own folder
I was practicing on my laptop in a coffee shop in Portland, trying to write a cleanup script that would remove old temp files. I had the paths mixed up and instead of pointing to a temp folder, I pointed it straight at my project folder where I kept all my practice exercises. Hit enter, watched the terminal spit out line after line of deleted files, and it took me maybe 10 seconds to realize what happened. I froze and just stared at the screen, then yanked the power cord since I didn't know how to stop the loop. I lost about 3 weeks of notes and small scripts, but thankfully my big projects were on GitHub. I keep a backup on a USB drive now, and I triple check every path before running anything. Has anyone else nuked something important and found a quick way to recover it before, or was I just extra unlucky?
1 comments
Log in to join the discussion
Log In1 Comment
roberts953d ago
Did you try any file recovery tools after you yanked the power? I've been in the same boat (not with my own folder, but with a client's database backup once, which was way worse). The trick is to stop using that drive immediately, because new writes can overwrite the deleted files. I had decent luck with PhotoRec on Linux, it got back most of my text files, though the folder structure was a mess. But honestly, the real fix is what you already did, backups and triple-checking paths. I also started writing my scripts to print the target path and ask for a "yes" confirmation before doing anything destructive, it's saved me more than once.
8