Use this guide when you keep doing the same file chore by hand, such as renaming photos or sorting downloads into folders. You need Python installed, a code editor and a folder of sample files.
Step by step
Describe the task in plain words
Write down exactly what you do by hand, step by step, for example 'for each file in Downloads, if it ends in .pdf move it to a PDFs folder'. Note any exceptions, such as files with the same name. This description becomes the outline for your script.
Make a safe test copy
Copy a handful of sample files into a new test folder and work only on that. Never run a new script on your only copy of important files. Make sure your real files are backed up before you ever point the script at them.
List the files first
Start a script that uses Python's built-in pathlib module to find the test folder and print the name of each file in it. Run it and check the list is what you expect. Getting the list right first means later steps only touch the files you intend.
Do a dry run
Add the logic that decides what should happen to each file, such as its new name or destination, but only print it for now. Read the output carefully and fix any mistakes. A dry run shows you the result without changing anything.
Make the changes
Once the dry run looks right, add the lines that actually rename, move or copy the files. Add a check so the script skips any file whose new name already exists, rather than overwriting it. Run it on the test folder and inspect the results in your file manager.
Use it for real and keep it
Point the script at the real folder only when you are happy with the test results and have a backup. Keep the script in a projects folder with a comment at the top explaining what it does and how to run it. Consider adding a setting at the top that switches between dry run and real run.
Ready-to-use checklist
- Task written in plain steps
- Test folder with copied files
- Real files backed up
- Script lists the right files
- Dry run output checked
- Overwrite protection added
- Test run results inspected
- Script saved with a comment explaining it
Practical tips
- Use pathlib rather than building file paths with string joins; it handles Windows and Mac differences for you.
- Print a short summary at the end, such as how many files were moved and skipped.
- If you use an AI assistant to help write the script, read every line and test it on copies first.
Common problems
The script says the file or folder cannot be found.
Print the full path the script is using and compare it with the real location. Check for typos, and remember paths are relative to the folder you ran the script from unless you give a full path.
Some files were overwritten because they had the same name.
Restore them from your backup, then add a check that skips or adds a number to any name that already exists. Test again on copies.
You get a permission error on some files.
The files may be open in another program or in a protected folder. Close other programs, and work on folders inside your own user area.
This guide gives general information, not personal legal, financial or medical advice. Rules and prices change, so check the current position with the official service before acting.
This guide is free. Unlock all ABCDayZ guides from £3.99 – one payment, no automatic renewal.