๐ŸŽ™ Free live masterclass ยท Sun, 29 Nov, 7:00 pm IST ยท Java Full Stack roadmap Register free โ†’
Skills101

Downloads folder organiser

A script that sorts a messy folder into Images, Documents, Videos and more, safely and with an undo log.

Beginnerโฑ 3โ€“4 hours๐Ÿชœ 7 stepsPythonpathlibshutil

What you'll learn

  • โ—†Working with files using pathlib
  • โ—†Moving files safely with shutil
  • โ—†Logging and dry-run modes

What you'll build

  • โœ“Sort files by extension into folders
  • โœ“Never overwrite: renames duplicates
  • โœ“--dry-run shows what would happen
  • โœ“Undo using the move log

Step-by-step guide

  1. 1

    Map extensions to folders

    Create a dict like {"Images": [".jpg", ".png"], "Documents": [".pdf", ".docx"], ...} and invert it to look up a folder by extension.

  2. 2

    List files

    Use Path(folder).iterdir() and skip sub-folders and hidden files.

  3. 3

    Move safely

    Create the target folder with mkdir(exist_ok=True). If a file with the same name exists, add " (1)", " (2)" before the extension.

  4. 4

    Add a dry run

    With argparse, add --dry-run that only prints "file โ†’ folder" without moving anything.

  5. 5

    Log every move

    Append each move as a JSON line {"from": ..., "to": ...} to moves.log.

  6. 6

    Implement undo

    Read moves.log backwards and move each file back, then clear the log.

  7. 7

    Schedule it

    Run it daily with Windows Task Scheduler or cron (0 21 * * * python organise.py ~/Downloads).

๐Ÿš€ Make it stand out

  • +Watch the folder live with the watchdog library
  • +Sort photos by the date they were taken (EXIF)
  • +Detect duplicate files by hash