Photos
How to Sort Photos into Folders by Date Taken on Mac and Windows
Sort photos into Year and Month folders by the date they were taken, not the file date: exact commands for three tools, a dry run, and what to do with undated files.
You have thousands of photos in one folder, or in a mix of old folders, and you want them in folders like 2019/08. To sort photos into folders by date taken, a tool must read the date stored inside each photo, not the date of the file. This guide shows three tools that do this, with the exact commands, a dry run you can do first, and what to do with the photos that have no date taken at all.
The short answer: copy the photos to a working folder, run a dry run with ExifTool or Phockup, check where a few known photos would go, then run the real command. Handle the undated photos at the end, by hand.
Date taken is not the file date
Every photo file has two kinds of dates.
- Date taken. The camera or phone writes it inside the photo when you press the shutter. In EXIF metadata it is usually the tag
DateTimeOriginal. It travels with the photo when you copy it. - File dates. Your computer keeps a created date and a modified date for each file. These often change when you download, copy or unzip a file. After a cloud export, many files show the day of the export.
If you sort by file date, a photo from 2016 can end up in the folder of the day you downloaded it.
Some files have no date taken at all. Screenshots and images saved from chat apps can lack it. Exports from cloud services can also keep the date in a separate file instead of inside the photo. If your photos come from Google Takeout, fix that first with Google Takeout photos with wrong dates. If they come from iCloud, see how to download photos from iCloud with the original date.
To see every date inside one photo, ExifTool has a command for it (ExifTool):
exiftool -a -G1 -s -time:all IMG_1234.jpg
Run it on three photos whose dates you know. If DateTimeOriginal is correct, the sorting will work. If it is missing, read the section on undated photos below before you start.
Before you start: work on a copy
All three tools below can move files, and a wrong path can scatter a whole library. Prepare like this:
- Copy the photos to a new folder, for example
~/Pictures/to-sorton a Mac orD:/to-sorton Windows. - Create an empty destination folder, for example
~/Pictures/sortedorD:/sorted. - Keep the original folder, or the original zip files, until you have checked the result.
- Make sure the disk has room for a second copy. If it does not, use a move option, but only on the copy you made in step 1.
Method 1: ExifTool (Mac, Windows, Linux)
ExifTool is a command-line program that reads and writes metadata. It is available as a Windows executable and a macOS package (ExifTool). On Windows, rename exiftool(-k).exe to exiftool.exe to use it from the command line, as the download page explains.
ExifTool sorts files by writing a new file name that contains a folder path built from a date. Its documentation shows how to use DateTimeOriginal if it exists and otherwise CreateDate. Arguments are read from left to right, and the last valid one wins (ExifTool).
Step 1: dry run
The TestName tag accepts a full path and prints the old and new names without changing anything. On a Mac, in Terminal:
exiftool -r -d ~/Pictures/sorted/%Y/%m/%%f%%-c.%%e '-testname<createdate' '-testname<datetimeoriginal' ~/Pictures/to-sort
This leaves out the file date on purpose. Photos without a date taken are reported as not changed, so you can see how many there are. The %%-c part adds a copy number, such as -1, only when a file with the same name already exists in the target folder.
Step 2: copy into Year / Month folders
exiftool -o . -P -r -d ~/Pictures/sorted/%Y/%m/%%f%%-c.%%e '-filename<createdate' '-filename<datetimeoriginal' ~/Pictures/to-sort
What each part does, according to the documentation:
-o .makes ExifTool copy the files instead of moving them. With this option ExifTool writes a new copy of each file. The image itself is not changed (ExifTool).-Pkeeps the file modified date of the original on the copy (ExifTool documentation). Without it, every copy gets the date and time of the copy as its modified date. The same page notes that-Pdoes not keep the file created date on Mac and on some Windows setups.- Existing files are never overwritten. With
%%-cin the name, a clash gets a copy number instead.
On Windows, in Command Prompt, use double quotes instead of single quotes:
exiftool -o . -P -r -d D:/sorted/%Y/%m/%%f%%-c.%%e "-filename<createdate" "-filename<datetimeoriginal" D:/to-sort
In a Windows batch file, every % must be written twice again, so %Y becomes %%Y and %%f becomes %%%%f. To get folder names like 2019/08-Aug, change %Y/%m to %Y/%m-%b.
If you also want undated photos sorted by file date, add -filename<filemodifydate as the first date argument. Do this only if you trust the file dates, which is rarely true after an export.
Method 2: Phockup (copies by default, keeps an "unknown" folder)
Phockup is an open-source tool that copies photos and videos into folders by year, month and day. It renames files by date by default, and it does not change file contents. Files without a date go into a folder called unknown, so every input file has a copy in the output (Phockup).
On a Mac it installs with Homebrew:
brew tap ivandokov/homebrew-contrib
brew install phockup
On Windows the README describes a manual setup: install Python 3, download Phockup, put exiftool.exe in the Phockup folder and run phockup.py.
Then:
- Dry run, with Year / Month folders and the original file names: ``
phockup ~/Pictures/to-sort ~/Pictures/sorted --date YYYY/MM --original-names --dry-run`` - If the plan looks right, run the same command without
--dry-run. - Open the
unknownfolder and deal with those files by hand.
Two options help with difficult files. --date-field=DateTimeOriginal tells Phockup which date tag to read when it picks the wrong one. --timestamp uses the file modified date as a last resort; the README warns that it may not be accurate. Phockup also compares checksums: an identical file that is already in the destination is skipped.
Method 3: SortPhotos (watch the default date rule)
SortPhotos is a Python script that also uses ExifTool. It needs Python and Perl. Its default folders look like 2010/06-Jun (SortPhotos).
Two defaults need attention:
- It moves files by default. Add
-cto copy. - It looks at all metadata that has a date and uses the oldest one, file dates included. Add
--ignore-groups Fileso that file dates are not used. Files with no other date then stay where they are.
A safe command, run first in test mode with -t:
python sortphotos.py -r -c -t ~/Pictures/to-sort ~/Pictures/sorted --ignore-groups File
Keep the two folder paths before --ignore-groups, as the README does. That option accepts several group names, so paths written after it are read as group names and the command fails. Remove -t to run it for real.
The README also describes an --extensions option that limits the file types, but the current script on GitHub does not list it. Run python sortphotos.py -h to see which options your copy accepts.
Undated photos and duplicates
After any of the three methods, some files are left over: in Phockup's unknown folder, or still in your working folder. Screenshots often have the date in the file name, and Phockup's --regex option can read a date from file names. For the rest, sort by hand or keep one folder named undated.
Each tool treats duplicates in its own way:
- Phockup compares checksums. It skips an identical file and gives a number to a different file with the same name.
- SortPhotos checks the name first. If a file with the same name exists and the content is exactly the same, it skips the new one. If the content differs, it adds a number such as
_1. The option--keep-duplicatesturns off the content check (SortPhotos). - ExifTool never overwrites, and with
%%-cit adds a copy number. It does not compare contents, so two identical photos with the same name end up side by side, for exampleIMG_1234.jpgandIMG_1234-1.jpg.
None of the three finds identical photos that have different names. For that you need a separate duplicate finder, run after sorting.
If you prefer a program with windows and buttons, some photo managers include a sorting wizard. Zoner Studio, a photo editor, has a "Sort Pictures" wizard that copies pictures into a new folder structure by date taken, with a custom option for other levels (Zoner Studio Help).
A Pacix Labs option for exports and old backups
PHOTOK is a Pacix Labs desktop app for Mac and Windows. Its page says it sorts a messy Google Takeout, iCloud export or old backup into Year / Month / Place folders, sets duplicates aside, and keeps everything on your computer. It offers a free preview, and the page lists a one-time price of €49. The page does not explain which date it reads, so run the preview on a copy and check where a few photos you know would go.
The free tools above do the date sorting well if you are comfortable with the command line. What PHOTOK adds is a place level in the folder names and a window-based app instead of commands.
Checklist
- Check
DateTimeOriginalin three photos withexiftool -a -G1 -s -time:all. - Fix Google Takeout or iCloud dates first if the date taken is missing.
- Copy the photos to a working folder and keep the originals.
- Run a dry run:
-testnamein ExifTool,--dry-runin Phockup,-tin SortPhotos. - Check where three known photos would go.
- Run the real command, copying rather than moving when you have the space. With ExifTool, add
-Pto keep the file dates. - Handle the undated files and duplicates by hand.
- Delete the originals only after you have checked the sorted folders and have another backup.
Frequently asked questions
What is the difference between date taken and date modified?
Date taken is stored inside the photo by the camera or phone, usually in the EXIF tag DateTimeOriginal. Date modified belongs to the file on your disk and often changes when the file is copied, downloaded or extracted from a zip. To sort by the moment the photo was taken, a tool must read the date inside the photo.
Why do some photos end up in the wrong year?
Usually the photo has no date taken inside it, and the tool used the file date instead. Screenshots, images saved from messaging apps and some exports have no date taken. Check one of these files with exiftool -a -G1 -s -time:all and decide by hand where it belongs.
Does sorting photos into folders change the photos?
Moving or renaming a file does not change the image. With the -o option, which this guide uses to copy, ExifTool writes a new copy of each file instead of only moving it, as its documentation explains. The image stays the same, but the copy gets a new file modified date unless you add -P, which keeps the date of the original. Always work on a copy of your library.
Can I sort videos by date taken too?
Yes. Phockup handles images and videos by default, and SortPhotos works with any file but works best with files that contain metadata. With ExifTool, use the -ext option if a video type is not processed, as described in its documentation.
What happens to duplicate photos when I sort?
It depends on the tool. Phockup compares checksums: an identical file is skipped and a different file with the same name gets a number. SortPhotos also skips a file when a file with the same name and exactly the same content already exists, unless you add --keep-duplicates. ExifTool never overwrites a file; with %-c in the name it adds a copy number, but it does not compare contents, so two identical photos can end up side by side.