1
\$\begingroup\$

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.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ It's probably possible, but more details on the directory path would be needed. Is the folder name just the year or are there other numbers in the path? \$\endgroup\$
    – StarGeek
    Jan 2, 2021 at 16:26
  • 1
    \$\begingroup\$ Exiftool can change the date to whatever you want it to be, so the question then becomes how do you determine the value that you want the date to be set to? Batch mode parsing the directory tree to obtain that value is going to be a function of the OS that you are using. Which to me suggests that this is not primarily a photography question, and may be better answered on another (OS dependent) SE site \$\endgroup\$
    – Peter M
    Jan 2, 2021 at 18:14
  • \$\begingroup\$ Almost certainly it is possible by writing a “relatively’ simple computer program using a shell or scripting language. The relatively depends on your relative programming proficiency and the pleasure you find in such tasks. \$\endgroup\$ Jan 3, 2021 at 14:19
  • \$\begingroup\$ @StarGeek The directory names are just the plain years. I edited the question accordingly. \$\endgroup\$
    – cirko
    Jan 3, 2021 at 17:05
  • \$\begingroup\$ @PeterM I thought it might be similar to this question, that's why I ended up posting it here \$\endgroup\$
    – cirko
    Jan 3, 2021 at 17:07

1 Answer 1

2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ I'm on a Mac. I did it from the parent directory and had to change it to exiftool '-Alldates<${Directory;m/(\d{4})/$_=$1} 0101 000000' * -r -overwrite_original for it to work. I got the Warning: syntax error for 'Directory' - (path/filename) for every single file (is that serious?), but it did change the Exifs, so - it works! \$\endgroup\$
    – cirko
    Jan 3, 2021 at 20:53
  • \$\begingroup\$ Ooops, I forgot a semicolon before the $_ (fixed). Double check to make sure it worked correctly but it still might have worked if there were no extra numbers in the Directory path exiftool received. I think that's why it worked regardless of my error. \$\endgroup\$
    – StarGeek
    Jan 3, 2021 at 21:14

Your Answer

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

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