I have lots of photos with non-existent exif dates where the write date is not correct. The original dates disappeared during a hard drive replacement. But they are in folders with the correct date.

Example: folder name "2003-01-22" contains photos with writing date 2017-05-20.

I want to be able to change / add exif and write the date based on the folder name.

Any good ideas?


1 Answer 1


Assuming there are no other numbers in the directory path, you could use
exiftool "-AllDates<$Directory 00:00:00" /path/to/files

That would set the EXIF timestamps to midnight on the date in the filepath.

If there are other numbers in the directory path, then a complex command would have to be used. Assuming the date is exactly as you posted
exiftool "-AllDates<${Directory;m/(\d{4}-\d\d-\d\d)/;$_=$1} 00:00:00" /path/to/files

These commands cannot be run from that directory, i.e. using a dot to indicate the directory. They must be run from above that directory using the -r (-recurse) option or must include the date as part of the indicated path, e.g. /path/to/2003-01-22/.

This command also does not affect the file system time stamps. To set those as well, duplicate the center part but replace AllDates with FileModifyDate or FileCreateDate.

This command will overwrite any existing timestamps, so make sure you're processing the correct files (see the -wm (-writemode) option for ways to alter this). This command creates backup files. Add -overwrite_original to suppress the creation of backup files. If this command is run under Unix/Mac, reverse any double/single quotes to avoid bash interpretation.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.