TransWikia.com

Exiftool: batch change date to year specified in directory name

Photography Asked by cirko on January 4, 2021

I have my old scanned photographs sorted in folders named by the year they were probably taken (1970, 1971 etc); the folder names are just the plain years without any other text. Is it possible to let ExifTool change the Exif date to, say 1.1.<foldername> for all files in the various folders? (January 1st just because no more specific date is known at this point) Any other (free) tool is of course as appreciated.

One Answer

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.

Correct answer by StarGeek on January 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP