💡
8

Showerthought: My first Python script deleted my entire 'Documents' folder last month.

I wrote a loop to clean up some text files but messed up the path variable, so it just wiped everything. Anyone know a good way to practice file operations without risking your actual stuff?
4 comments

Log in to join the discussion

Log In
4 Comments
ninar12
ninar122mo ago
Have you thought about using version control like Git for your scripts before you run them? That way you could roll back the code that caused the wipe. Sage_green's virtual machine idea is great for total safety, but a simple commit gives you a snapshot to fall back on if your logic goes wrong. It adds a step, but it forces you to pause and check your work. I started doing this after a similar scare with a batch rename script.
3
the_jennifer
Oof, that "messed up the path variable" fear is why I still use a dummy folder full of junk files for testing.
2
williams.sage
Oh man, I still do the dummy folder thing too (and somehow always name it something boring like "test" and then forget what's actually in there). I tell myself I'll just be extra careful and it'll be fine, but the truth is I've accidentally nuked that dummy folder more times than I care to admit. At this point I'm basically testing my ability to recover from my own mistakes rather than testing the actual script. Sad little cycle, really, but at least my real files are safe.
5
sage_green
sage_green2mo ago
Yeah, that dummy folder trick is a lifesaver... honestly, setting up a whole separate virtual machine just for testing scripts saved me so many headaches. It's a bit of work upfront but then you can just go wild in there. Nothing you do in that sandbox can touch your actual system files. Totally kills that anxiety about breaking your main environment.
2