r/Python • u/One-Type-2842 • Mar 25 '26
Discussion File Handling Is Hard If You Made Single Line Mistake!
Recently, I have Created a program just to copy all of the webpages I have downloaded from chrome. It is Because, In case if any Deletion occurred to Original files I can still access copied files where it resides
Assumption :
• Webpages Downloaded from chrome have no extension.
• Downloaded webpage files Stores in Mobile's File-Manager /sdcard/Download.
• Some files in /sdcard/Download are Unnecessary that are no of my use (text based but no extension).
Program :
I Imported shutil, os, pathlib to Create Program. I made a single mistake In Copying the filename it was :
shutil.copy(absolute_filename, absolute_dir)
My mistake was I Entered wrong absolute_filename to copy in directory. Now The files in /sdcard/Download are moved to absolute_dir. Which Results in Removal from the Chrome's Download section..
Would Anyone suggest my best practices against this. I lost all of the downloaded webpages (~70)
1
u/fazzah SQLAlchemy | PyQt | reportlab Mar 25 '26
We have dry run options for destructive scripts for a reason
1
u/ConcreteExist Mar 25 '26
Run a test that only says what it will do before you run a command that will permanently destroy files.
3
u/Designer-Ad-2136 Mar 25 '26
Yeah. A lesson you gotta learn the hard way. Now, I write all of my housekeeping scripts so that it prints out the directories followed by "input('press enter to continue')"