21
My first Python script deleted my entire 'Documents' folder last Tuesday
I was trying to write a simple program to organize some old text files. I used the 'os' module to find and move files, but I messed up the path in my loop. Instead of moving files from a test folder, it started deleting everything from my main Documents directory. I watched in horror as years of photos and tax info vanished. Has anyone else made a huge mistake with file paths, and how do you test your scripts safely?
3 comments
Log in to join the discussion
Log In3 Comments
holly_green8220d ago
Oh man, my buddy did something like that with a batch file once. He meant to clean his downloads folder but wiped his whole desktop instead.
8
Welcome to the club, it's a rite of passage. I always run those scripts in a totally empty test folder now, with no important files even on the same drive. @drewc62 has the right idea about using test data, but you have to make the test area a safe sandbox. Honestly, the sheer panic of watching files disappear is a lesson you only need once. My heart still skips a beat every time I use os.remove.
7