I keep my images in folders for each year (1995, 1996, 1997....) with sub-folders for events. Some of my exif dates are correct. Some are not. I was hoping to go through each year's folder and make sure that each photo's exif's year (and only the year) is the same as the folder. It would need to recursively go through all of the sub-folders and sub-folders within each year's folder. I've looked at "date setting" options and "date shifting" options, but I want to leave the day and month alone if they exist (and I guess just arbitrarily decide a day and month if none exist). I just want to change the year of every photo to the year of its root folder without changing days and months.
Thanks in advance.
Mike
With this config file,
%Image::ExifTool::UserDefined = (
'Image::ExifTool::Composite' => {
FixedDateTime => {
Require => {
0 => 'DateTimeOriginal',
1 => 'Directory',
},
# take first 4-digits in directory name as the year,
# and use this to replace year in date/time
ValueConv => q{
$val[1] =~ /(\d{4})/ or return undef;
my $dirYear = $1;
$val[0] =~ s/^\d{4}/$dirYear/ or return undef;
return $val[0];
},
},
},
);
1; #end
This command may do what you want:
exiftool -if "$fixeddatetime ne $datetimeoriginal" "-datetimeoriginal<fixeddatetime" -r BASE_DIR
where BASE_DIR is the base directory containing all of your images. Note: Use single quotes around the arguments containing a $ symbol on Mac/Linux, or double quotes as above in Windows. Also note that I have assumed the year is the first consecutive 4 digits in the directory name.
This only changes DateTimeOriginal, but there may be other date/time tags you also want to change.
Let me know if you have any questions. See the sample config file (https://exiftool.org/config.html) for instructions on how to activate a config file.
- Phil
Old post, I know... I have followed Phil's suggested code and saved it as ".ExifTool_config" in the same directory that ExifTool application is installed (usr/local/bin). When I run the command,
exiftool -if "$fixeddatetime ne $datetimeoriginal" "-datetimeoriginal<fixeddatetime" -r BASE_DIR
(where BASE_DIR is the parent directory where images are stored), I get this error:
1 directories scanned
36 files failed condition
0 image files read
I'm trying to change the YEAR only of the datetimeoriginal tag to the first four characters of the folder name (could also use the file name - they're the same). The Folder Name is 1957 Carthage MO and all of the files start with that name and end with a unique number. All of the files have an incorrect datetimeoriginal in the EXIF data.
In my case, all datetimeoriginal entries are INCORRECT, so I really don't need to verify the current date. I've tried just running this:
ExifTool '-datetimeoriginal<fixeddatetime'
on a single file, I get this error:
Warning: No writable tags set from /Users/ozarksreef/Desktop/1957 Carthage MO/1957 Carthage MO-612.jpg
0 image files updated
1 image files unchanged
Is the problem that the config file is not running? If so, how do I fix this? Any help appreciated!
What do you get with this command for one of your files?:
exiftool -datetimeoriginal -fixeddatetime FILE
- Phil
It returns: Date/Time Original : 2015:01:18 12:00:00
This date/time is applied to all of the photos
Quote from: Ozarksreef on December 02, 2020, 02:54:05 PM
Is the problem that the config file is not running? If so, how do I fix this? Any help appreciated!
Sounds like it. Take a look at FAQ #11 (https://exiftool.org/faq.html#Q11).
I've tried 3 of the 4 suggestions for ensuring that it is running. The fourth suggestion is running the confit file by name. What name do I use 1 the config file name or do I have to name it within the file itself?
Just call it whatever you want, then start the command with this:
exiftool -config c:\path\to\your\config\file.config ...
- Phil