🎙️
15

Warning: My first Python script deleted my whole project folder

I was learning file operations in Python last weekend and ran a script that was supposed to clean up some test files. Instead, it recursively deleted my entire coding practice folder with 3 months of work in it. Has anyone else accidentally trashed their own files with a rookie script?
3 comments

Log in to join the discussion

Log In
3 Comments
grantmartinez
That "brutal way to learn" line really hit home for me. I've been there with a bad shell script that nuked my entire music collection back in 2005. Luckily you didn't have something like a nas or external drive plugged in because those can get caught in the crossfire too.
2
the_emery
the_emery1mo ago
Three months of work? Man, I would have been sick to my stomach (and probably cried a little). That's a brutal way to learn about relative paths versus absolute ones, especially with recursive deletes. Hopefully you had some kind of backup or version control hidden somewhere.
1
jamesm38
jamesm3816d ago
Wait, did you manage to actually recover any of it with a file recovery tool after that? I've heard some people swear by PhotoRec for stuff like this, but I've never had to use it myself. Honestly though, the crying part isn't even an exaggeration. I had a similar moment when I accidentally overwrote a project folder with an empty one because I got my directory paths mixed up in a script. The sick feeling in your stomach is real. On the bright side, it's the kind of mistake you only make once. After that, you start triple-checking every rm command and probably alias it to something safer, like 'rm -i' or 'trash-cli'.
4