← BACK TO THE SIMPLE VERSION
PROPER INSTRUCTIONS

Automate the organisation of your Downloads folder: proper instructions

Photograph of a row of neatly organized red ring binders on a shelf, representing sorted files.
Unsplash photo, free to use under the Unsplash License (source page); photographer credit was not available in the retrievable source extract.

A Downloads folder becomes hard to search when installers, invoices, photographs and repeated filenames accumulate. This guide makes a conservative Python organiser for a personal computer. It moves only ordinary files in the top level of Downloads into Downloads/Organised/YYYY-MM folders by category. It does not delete files, process subfolders or follow links. It first prints a proposed move list; actual movement happens only when you add an explicit option. This is deliberately safer than a program that silently rearranges everything. The date is the file modification month, because a portable local program cannot depend on a browser download-date field.

Prerequisites

• Python 3.9 or later. Check with python3 --version, or with py --version on many Windows computers.

• Permission to read and write your account’s Downloads folder.

• A terminal and a plain-text editor.

• A backup of important files. Moving normally preserves content but a backup is still the recovery boundary.

Numbered actions

1. Make a folder named downloads-organiser in your home directory. Do not place the script in Downloads, because it would itself be a candidate for sorting.

2. Create organise_downloads.py and paste this program.

from pathlib import Path
from datetime import datetime
import argparse, shutil
d=Path.home()/"Downloads"; root=d/"Organised"
groups={"Documents":{".pdf",".txt",".docx",".csv",".xlsx"},"Images":{".jpg",".jpeg",".png",".gif",".webp"},"Audio":{".mp3",".m4a",".wav",".flac"},"Video":{".mp4",".mov",".mkv",".webm"},"Archives":{".zip",".tar",".gz",".7z"},"Installers":{".exe",".msi",".dmg",".pkg",".deb",".rpm"}}
apply="--apply" in __import__("sys").argv
for f in d.iterdir():
    if f.name.startswith(".") or f==root or not f.is_file(): continue
    kind=next((k for k,v in groups.items() if f.suffix.lower() in v),"Other")
    month=datetime.fromtimestamp(f.stat().st_mtime).strftime("%Y-%m")
    target=root/month/kind/f.name; n=1
    while target.exists():
        target=target.with_name(f"{f.stem} ({n}){f.suffix}"); n+=1
    print(f"{f.name} -> {target.relative_to(d)}")
    if apply: target.parent.mkdir(parents=True,exist_ok=True); shutil.move(str(f),str(target))

3. Run python3 organise_downloads.py without --apply. Read every printed destination. If Downloads is in OneDrive or elsewhere, change only the first path line to the exact location.

4. Create two harmless files, such as test-note.txt and test-image.jpg, in Downloads. Run the dry check again and verify their category and month.

5. Close open files, then run python3 organise_downloads.py --apply. On Windows use py if that is your Python launcher.

6. Use it manually for several successful runs before scheduling. A daily cron example is

0 18 * * * /usr/bin/python3 /home/yourname/downloads-organiser/organise_downloads.py --apply >> /home/yourname/downloads-organiser/organise.log 2>&1

Replace both paths. Windows users can create a daily Task Scheduler task with Program/script py and the full script path plus --apply as arguments.

Checking and testing

1. Open the two test files from their new destinations; successful movement is not enough if a file was inaccessible or synchronisation failed.

2. Run the program a second time. It should not re-sort anything in Organised because that directory is excluded.

3. Create a second file with the same name as an existing organised file. Confirm that the proposed destination gains a number rather than overwriting the earlier file.

4. Keep an audit record during early runs: python3 organise_downloads.py --apply | tee organise.log on macOS/Linux, or PowerShell Tee-Object.

Common mistakes

• Scheduling before reviewing dry-run output.

• Sorting folders as though they were files; projects and browser-support folders should remain intact.

• Assuming extension means content type. Unknown extensions intentionally go to Other.

• Ignoring files held open by another program, especially on Windows.

• Testing first in a cloud-synchronised folder without appreciating that a move changes the cloud path too.

Rollback and safety

Nothing is deleted. Disable the scheduled task before changing the rule or reverting files. Use the saved output log to move files from Organised back to Downloads with a file manager, beginning with important documents. Remove the Organised folder only after checking it is empty or intentionally archived. If a proposed move surprises you, do not use --apply; edit the category list or leave that extension under Other.

Choosing categories and maintaining the rule

Keep the initial classification small. A document and an image category are easy to understand; dozens of fine-grained folders make the automation less useful than search. File extensions are hints rather than a guarantee of a file’s contents. A CSV may be data from a bank, a shopping list or an application export, so the purpose here is retrieval rather than a semantic archive. If an extension appears in more than one possible group, place it in the group you would look in first, test it with a disposable file, and record the decision in a comment beside the groups dictionary.

Review the Organised folder monthly. If Other is filling with a repeatable legitimate type, add precisely that lower-case extension to one existing set, perform a dry run, and test a single file before the next scheduled run. Do not add a broad pattern such as every file beginning with a letter, and do not remove collision handling. The numbered suffix preserves both files even if two different downloads share a name. A move on one local disk is normally quick, but a cloud client or a network home directory can take time; allow sync to complete before assuming the result is backed up.

When not to use this automation

Exclude a folder that is used as an active hand-off location by accounting software, a scanner, a browser extension or a workplace synchronisation tool. These programs can expect an exact path. This program skips folders, but it will move files that appear at Downloads top level. If another tool watches that location, use a separate staging folder or retain manual sorting. Automation is successful only when it reduces routine work without breaking an agreed workflow.