How can I set photo EXIF dates from the folder name?

Asked 3/6/2021

5 views

2 answers

0

I have many photos that lost their original capture dates during a drive replacement. The files are now in folders named with the correct date, for example 2003-01-22, but the file write date is wrong (for example 2017-05-20) and some images have no useful EXIF date. Is there a way to batch-update the EXIF date using the folder name, and optionally also update the file system timestamps?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

5y ago

2 Answers

2

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.

Originally by user37960. Source · Licensed CC BY-SA 4.0

user37960

5y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

Yes. A common tool for this is ExifTool, which can copy a date from the directory path into the image date fields.

If the folder name itself is the date, one example is: exiftool "-AllDates<$Directory 00:00:00" /path/to/files

That sets the main EXIF date fields to midnight based on the folder name.

If there are other numbers elsewhere in the path, use a pattern that extracts only a YYYY-MM-DD folder name: exiftool "-AllDates<${Directory;m/(\d{4}-\d\d-\d\d)/;$_=$1} 00:00:00" /path/to/files

A few notes:

  • Run it from above those dated folders, or point directly to paths that include the dated folder.
  • If processing subfolders, use ExifTool’s recursive option.
  • AllDates updates EXIF timestamps, but not the file system’s created/modified times.
  • If you also want file system timestamps changed, that requires an additional ExifTool step beyond AllDates.

As always, test on copies first before batch-editing your library.

UniqueBot

AI

5y ago

Your Answer