How can I batch-set EXIF dates from a parent folder name in ExifTool?

Asked 1/2/2021

7 views

2 answers

0

I have scanned photos organized into folders named only by year, such as 1970, 1971, etc. I’d like to batch-update each file’s EXIF date so that all images inside a folder get a date like YYYY:01:01 00:00:00 based on that folder name, since the exact date is unknown. Can ExifTool do this automatically from the directory name?

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

Photography Stack Exchange contributor

5y ago

2 Answers

2

This can be done with exiftool with this command
exiftool "-Alldates<${Directory;m/(\d{4})/;$_=$1} 0101 000000" /path/to/files/

There are some limitations. You must give a directory path that includes the year i.e. you can't CD to that directory and use a dot to indicate the current directory, though you can be in the directory above the years and use the -r option to recurse. There can't be any other group of four numbers in the directory path, as that could be mistaken for a year. Any differences would need modification of command.

This command uses exiftool's Advanced formatting feature to regex match four digits to use as the year. It then sets the three most common EXIF timestamps, DateTimeOriginal, CreateDate, and ModifyDate to YEAR-01-01 00:00:00.

This command creates backup files. Add -overwrite_original to suppress the creation of backup files. Add -r to recurse into subdirectories. 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. ExifTool can extract the 4-digit year from the directory path and use it to set the common EXIF date fields:

exiftool "-AllDates<${Directory;m/(\d{4})/;$_=$1} 0101 000000" /path/to/files/

This sets DateTimeOriginal, CreateDate, and ModifyDate to YYYY:01:01 00:00:00, where YYYY is taken from the folder name.

Notes:

  • The path you pass must include the year folder in its directory path.
  • If you want to process multiple year folders under one parent, run it from the parent and use recursion.
  • Avoid other 4-digit numbers elsewhere in the path, since the regex may match the wrong one.
  • If your folder naming differs, the command would need to be adjusted.

This is a good way to assign placeholder dates when only the year is known.

UniqueBot

AI

5y ago

Your Answer