-
Notifications
You must be signed in to change notification settings - Fork 10
Documentation
SortPhotos is intended to be used primarily from the command line. To see all the options, invoke help
python sortphotos.py -h
The simplest usage is to specify a source directory (the directory where your mess of files is currently located) and a destination directory (where you want the files and directories to go). By default the source directory it is not searched recursively but that can changed with a flag as discussed below.
python sortphotos.py /Users/Me/MessyDirectory /Users/Me/Pictures
There are several options that can be invoked. For example the default behavior is to move files from your source directory to your destination directory. Note that it is much faster to move the files rather than copy them (especially if videos are involved). However, if you want to copy this is done with the -c
or --copy
flag.
python sortphotos.py -c /source /destination
By default, only the top level of the source directory is searched for files. This is useful if you dump photos into your top directory and then want them to sort. If you want to search recursively, use the -r
or --recursive
flag.
If you don't want to see details on file processing use the -s
or --silent
flag. It will still show overall progress.
If you just want to simulate what is going to happen with your command use the -t
or --test
flag. No files will be moved or copied, but all the moves will be simulated showing you how the files would be reorganized/renamed.
By default folders are sorted by year then month, with both the month number and name. So for example if cool_picture.jpg was taken on June 1, 2010 the resulting directory hierarchy will look like: 2010 > 06-Jun > cool_picture.jpg. However, you can customize the sorting style almost anyway you want. The script takes an optional argument -s
or --sort
, which accepts a format string using the conventions described here. To separate by subdirectory, just use a forward slash (even if you are on Windows). So for example, the default sorting behavior (2010/06-Jun) is equivalent to:
python sortphotos.py --sort %Y/%m-%b
Or you could sort just by month, but with the month full name (June):
python sortphotos.py --sort %B
Or you can sort by year without century, then week number, then an abbreviated day of the week (10/23/Sun)
python sortphotos.py --sort %y/%W/%a
The possibilities go on and on.
You can setup the script to automatically rename your files according to same convention. This uses the same conventions for directory sorting and are described here. For example you could rename all your files to contain the year, month, day, hour, and minute by using
python sortphotos.py --rename %Y_%m%d_%H%M
This would create files like: 2003_1031_1544.jpg. By default the script keeps the original name and the original extension. In all cases a unique digit in appended in the case of name collisions.
sortphotos.py uses Exiftool.py to search through all metadata that has date information and uses the metadata with the oldest date (which may be more than one metadata tag). For example, if "EXIF:CreateDate" is the tag with the oldest date it is automatically used. There are several filters you can use to restrict which grouops/tags to search through for the oldest date. All the groups/tags are described here (with a few extra ones here). One common usage is to ignore all file metadata which is not persistent (i.e., FileModifyDate, FileCreateDate, etc.). This is accomplished with:
python sortphotos.py source destination --ignore-groups File
This would search through all other groups (EXIF, JPG, etc.) looking for relevant date tags and keep the oldest, but would not use File timestamps. If there is no metadata (except file timestamp data) then the file will just stay where it is. You could also specify specific tags to ignore
python sortphotos.py source destination --ignore-tags File:FileModifyDate File:FileCreateDate
Alternatively you could specify the complete set of groups that you want to use
python sortphotos.py source destination --use-only-groups EXIF XMP IPTC
and this would only look for date tags in EXIF, XMP, IPTC. Or you could restrict to a specific set of tags
python sortphotos.py source destination --use-only-tags EXIF:CreateDate EXIF:DateTimeOriginal
You can also prioritize specific tags so as to not always use the oldest date
python sortphotos.py source destination --prioritize-tags EXIF:CreateDate EXIF:ModifyDate
or prioritize by group
python sortphotos.py source destination --prioritize-tags EXIF
Time zone adjust is meant to be done against UTC, however, some devices store local time. If this is the case and the local time stored is already correct, you can disable the time zone adjust.
python sortphotos.py --disable-time-zone-adjust /source /destination
SortPhotos will always check to make sure something with the same file name doesn't already exist where it's trying to write, so that you don't unintentionally overwrite a file. It this occurs it will append a number on the end of the file. So for example if photo.jpg was taken on June 1, 2010 but 2010 > June > photo.jpg already exists then the new file will be moved as photo_1.jpg and so on. SortPhotos will go one step further and if it finds a file of the same name, it will then run a file compare to see if the files are actually the same. If they are exactly the same, it will just skip the copy (or move) operation. This will prevent you from having duplicate files. However you have the option of turning this off (not the name comparison, that will always happen, just the weeding out of duplicates). This option would be useful, for example, if you are copying over a bunch of new photos that you are sure don't already exist in your organized collection of photos. Invoke the option --keep-duplicates
in order to skip duplicate detection.
python sortphotos.py --keep-duplicates /source /destination
You can ignore specified file extensions by specifying a list
python sortphotos.py --ignore-file-types MOV MP4 /source /destination
If you are taking photos for an event that goes past midnight, you might want the early morning photos to be grouped with those from the previous day. By default the new day begins at midnight, but if you wanted any photos taken before 4AM to be grouped with the previous day you can use
--day-begins 4
The argument to the flag should be an integer between 0-23 corresponding to the hours of the day starting at midnight.