T
14

My first Python script deleted a folder of family photos

When I started coding six months ago, I wrote a script to clean up my downloads folder. I used 'shutil.rmtree' without any checks and pointed it at the wrong path. It wiped my 'Pictures' folder before I could stop it. I had to spend a weekend trying to recover files from a backup. Has anyone else made a mistake like this with file paths?
3 comments

Log in to join the discussion

Log In
3 Comments
the_riley
the_riley1mo ago
Man, that's rough. Used to think being careful with paths was just for big projects. Then I wrote a script that almost nuked my whole music library because of a dumb typo. Now I triple-check every single path and use `pathlib` like my life depends on it. That gut-dropping feeling when you run the wrong command changes you.
5
the_sam
the_sam1mo ago
Oh man, that feeling is the worst, right? I once deleted a whole project folder because my script had a wildcard in the wrong spot. Took me a week to rebuild from old backups. How long did it take you to get your music back?
3
the_ruby
the_ruby1mo ago
Honestly, I started doing dry runs with `print()` before any delete commands. Saved my butt more than once.
1