Image Sorting Tool
Having been taking many thousands of pictures over the year, it’s crucial to have some way of structuring the photos to keep the upper hand. My approach was to make a first layer of folders for the year, then subfolders for the months, and another layer of subfolders for the days, which will look like:
photos/
├── 2025/
│ ├── 2025-01/
│ │ ├── 2025-01-13/
│ │ │ └── ...
│ │ └── 2025-01-26/
│ │ └── ...
│ └── 2025-02
└── 2024/
└── 2024-03/
└── 2024-03-17/
└── ...
the only command line tool that is able to do that is exiftool, but I wanted to do my own.
The Sorter
That’s how the sorter was born. A python based command line tool that sorts images and other files into folders, according to their date. The tool is open source on GitHub, in this repository.
Example Command
Here a short example on how the tool works, if the command is run inside the repository.
Note: Always use the --dry
flag, unless you want changes written to disk.
python3 main.py --input . -r --output . --pattern "year-%Y" "%y-%b" --dry
The user will be asked prompts on how to deal with collisions, as in this example the sorting would lead files with the same name placed in the same folder. One can either abort, only have the first appearance of the file copied or moved, or have the tool rename the files.
This command would sort the file in the repository into the folders:
year-2025/
25-Sep/
requirements.txt
...
25-Jun/
python3
...
Explanation of the command:
-
--input .
we take all the files in the current folder -
-r
recurse into subdirectories and look at those files too -
--output .
sort the files into the current folder -
--pattern "year-%Y" "%y-%b"
the folders into which the files will be sorted, containing strftime format codes"year-%Y"
the first pattern will lead to the first layer of folders asyear-2024
,year-2025
and so on.%Y
will be replaced with the files year."%y-%b"
, the second pattern, will lead to subfolders with the format25-Sep
,25-Jun
, as%y
will be replaced with the year without the century, and%b
with the months abbreviation.- the user can freely customize the number of sub folders and their names. if not specified, the default is three subfolders:
2025/2025-05/2025-05-12
.
-
--dry
no folders will be created and no changes will be written to disk. besides that, the program will run as usual