Modify only the year

Started by mikebw, October 14, 2011, 03:38:43 PM

Previous topic - Next topic

mikebw

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

Phil Harvey

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 for instructions on how to activate a config file.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Ozarksreef

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!


Phil Harvey

What do you get with this command for one of your files?:

exiftool -datetimeoriginal -fixeddatetime FILE

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Ozarksreef

It returns: Date/Time Original              : 2015:01:18 12:00:00

This date/time is applied to all of the photos

StarGeek

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.

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Ozarksreef

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?

Phil Harvey

Just call it whatever you want, then start the command with this:

exiftool -config c:\path\to\your\config\file.config ...

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).