Automate file organization in Python: A small script that works on an 8GB mini PC
A small Python script to organize the Downloads folder by extension into subfolders. No GPU needed, no extra libraries, and it finishes in an instant on an 8GB mini PC.
Automation is best learned by starting with file organization. It doesn't need a screen, just commands, so even on an 8GB / no external GPU mini PC, the burden is almost zero. This article shows how to create a script that sorts the Downloads folder by extension.
Result: Organizing about 300 files completed in under 2 seconds. Works with the standard library only, no additional installation required. Before running, don't forget to back up important files.
What we're creating
Move the contents of the Downloads folder to subfolders like this:
- Images: jpg / png / gif / webp
- Documents: pdf / docx / xlsx / pptx
- Archives: zip / 7z / rar
- Videos: mp4 / mov / mkv
- Other: Anything else
The script
from pathlib import Path
import shutil
TARGET = Path.home() / "Downloads"
RULES = {
"Images": {".jpg", ".jpeg", ".png", ".gif", ".webp"},
"Documents": {".pdf", ".docx", ".xlsx", ".pptx"},
"Archives": {".zip", ".7z", ".rar"},
"Videos": {".mp4", ".mov", ".mkv"},
}
def category_of(path: Path) -> str:
ext = path.suffix.lower()
for name, exts in RULES.items():
if ext in exts:
return name
return "Other"
for item in TARGET.iterdir():
if not item.is_file():
continue
folder = TARGET / category_of(item)
folder.mkdir(exist_ok=True)
shutil.move(str(item), str(folder / item.name))
print("Organization complete")
Before running, copy important files in the Downloads folder elsewhere. It's safer to try first in a test folder.
Make it safe to use
- Start with
TARGETpointing to a test folder - Try with a copy (
shutil.copy2) - Be careful when overwriting files with the same name
- Leave an execution log in a file
Once you're used to it, you can add processing like moving old files to a different folder based on modification date, or finding duplicate files. But don't try to do everything at once — start by making one process work reliably.
If you want it to run on a schedule
On Windows, register it with the Task Scheduler to run on PC startup or at a set time every day. Since it doesn't stay resident, it doesn't use PC RAM. On a laptop, the "on wake from sleep" option is easy to use.
Note: Automation is convenient, but it can delete important files. Take a backup the first time, and check the move destination and the log.
The same pattern works for images
Sorting files by extension and resizing images share the same shape: walk a folder, process one file at a time, and write the result somewhere else. Once this loop works, you can reuse it for images, PDFs, and spreadsheets. The image version is in Batch-resize images in Python.
Summary
File organization is a good introduction to Python automation. No extra libraries needed, no external GPU needed, finishes in a few seconds. Stack up small successes, then move on to the next automation.