Skip to content

Organizing Photos (or files) with a Custom Script

As a DevOps engineer, automation is second nature to me. But outside of work, I'm also into photography, and I own a Canon 80D. One of the biggest pains for me has always been sorting RAW files into manageable folders. The same applies to pictures exported from my phone—sorting them manually into year/month folders based on their creation date was tedious and error-prone.

Problem Statement

I initially sorted my photos by hand, moving them into appropriate folders based on their creation date. Over time, as my photo collection grew, this became unsustainable.

The problem with manual sorting

  • It's time-consuming.
  • Risk of human error.
  • Doesn't scale well for large datasets.

I needed an automated solution to handle this process efficiently.

The Journey to Automation

At first, I wrote a simple Bash script to do the job, but it quickly became apparent that I needed more flexibility. Enter Python!

Why Python?

  • Better File Handling: More powerful libraries for dealing with files and metadata.
  • Extensibility: Easier to add features later.
  • Cross-Platform Support: Works on Linux, macOS, and Windows.

After getting a basic version up and running, I decided to develop it further, adding:

  • CLI options for flexibility
  • Proper logging
  • Exclusion patterns
  • The ability to copy or move files

Ultimately, I decided to document it properly and open-source it, as others might find it useful.

Photo Organizer: The Final Script

Tests Upload Release PyPI version

Features

  • Organize photos into year/month/day folders based on creation date.
  • Move or copy files from the source to the target directory.
  • Recursively traverse directories.
  • Filter files by specified extensions.
  • Exclude files from processing using regex patterns.
  • Verbose logging for detailed information.
  • Flexible folder structure with optional top-level year-month folders.

Installation

The script is available as a pip package for easy installation:

pip install photo-organizer

Usage

photo-organizer [-h] [-r] [-d] [-e [ENDINGS [ENDINGS ...]]] [-v] [-c] [--no-year] [--exclude EXCLUDE_PATTERN] source target

Examples

Move all photos into year/month folders:

photo-organizer /path/to/source /path/to/target

Move photos recursively into year/month/day folders:

photo-organizer /path/to/source /path/to/target -r -d

Copy only .jpg and .png files:

photo-organizer /path/to/source /path/to/target -e .jpg .png -c

Exclude files matching a specific regex pattern:

photo-organizer /path/to/source /path/to/target --exclude "^ignore|\.tmp$"

Move photos into top-level year-month folders:

photo-organizer --no-year /path/to/source /path/to/target

Development & Contribution

This project is open-source, and contributions are welcome! You can find the source code at GitHub: Supporterino/photo-organizer.

If you find a bug or have an idea for a new feature, feel free to open an issue or submit a pull request.

🚀 Happy automating!