Using exiftool to write in filename either CreateDate or FileModifyDate, whatever exists.
What is the problem: -If no CreateDate exists, error is happening, and filename is not changed according to Creation date.
"Warning: No writable tags set from DSC_0680a.JPG"
How can I tell exiftool to write either CreateDate or FileModifyDate - whatever exists in exif information?
Currently, I am using the following command:
for pic in DSC*.*; do exiftool "-FileName<CreateDate" -d ${pic//.*}_%Y%m%d_%H%M%S.jpg" "$pic"; done;
This does not work too:
exiftool "-FileName<CreateDate" -d "DSC_0680a_%Y%m%d_%H%M%S.jpg" DSC_0680a.JPG || exiftool "-FileName<FileModifyDate" -d "DSC_0680a_%Y%m%d_%H%M%S.jpg" DSC_0680a.JPG
Using exiftool in a loop can greatly extend processing time as the startup is its biggest performance hit (see ExifTool Common Mistake #3).
You don't need two separate exiftool commands. You can put both options in the same command and exiftool will use the last valid option (see Note #1 under the -TAG[+-^]=[VALUE]
option).
You could use
exiftool "-FileName<FileModifyDate" "-FileName<CreateDate" -d "%%f_%Y%m%d_%H%M%S.%%e" /path/to/files/
and exiftool will fallback on FileModifyDate
if CreateDate
doesn't exist
Here I did remove the ${pic//.*}
and replaced it with exiftool's %f
and %e
variables, which stand for the Filename and Extension respectively (see the -w
(-TextOut
) option). When used in a date format string, the percent signs for filename variables need to be doubled.
It should be noted that if used in a Windows Bat file, then all percent signs need to be doubled, which would result in a -d
(-dateFormat
) string of %%%%f_%%Y%%m%%d_%%H%%M%%S.%%%%e
(see ExifTool FAQ #27).