Use of Composite Tags instead of DateTimeOriginal with -filename and -directory

Started by Brooks, July 26, 2015, 03:49:49 PM

Previous topic - Next topic

Brooks

Hi Phil,

I am using exifTool version 9.98 and I am having the following problem:

I created 2 different @ Arg files

One uses the Tag "DateTimeOriginal" works correctly with the -d %Y/%Y_%m_%d/

One other uses a Composite tag called "DateTime2" instead of the Tag "DateTimeOriginal"

All other settings are 100% identical

I created the "DateTime2" Composite tag to resolves any missing, null, and dates such as "0000:00:00 00:00:00.00" by validating 'DateTimeOriginal', 'CreateDate', 'ModifyDate', 'FileModifyDate' in that order.

What I am finding is that when using the "DateTime2" Composite tag, it is ignoring the -d %Y/%Y_%m_%d/ formating and tries to insert the the date as "2012:06:28 08:59:07".

I have tried all combinations of -o, -directory, -d, and -filename and tried to pass the $(DateTime2) with both -directory and -filename with no success.

My only work-around was to create Composite tags "Year" and "DatedFolder" and use those with -filename and removing the -d and -directory options

  -filename<P:\Original/${Year}/${DatedFolder}/%f%-2c.%e
 
Any thoughts on how best to resolve the issue that -d does not work if the date being used is a Composite tag?

By the way, I get the same results weather I used -filename or -testname. Meaning files with DateTimeOriginal tag will get copied from source to target.

-Brooks

# ------------------------------------------------------
# F:\exifTool\CopyOriginals-1.arg -- Uses -directory<P:\Original/${DateTimeOriginal}
# ------------------------------------------------------
# Move Original Files
-P
-o
.
-d
%Y/%Y_%m_%d/
-directory<P:\Original/${DateTimeOriginal}
-filename<%f%-2c.%e
-Execute
# --------------------------------------------


exiftool -config "F:\exifTool\.Exiftool_config" -@ "F:\exifTool\CopyOriginals-1.arg" -common_args -r -ext jpg "F:\TestPhotos"

Results:
Warning: [minor] Tag 'DateTimeOriginal' not defined - F:/TestPhotos/011.jpg
Warning: No writable tags set from F:/TestPhotos/011.jpg
Error: './011.jpg' already exists - F:/TestPhotos/011.jpg
Warning: Invalid tag name '%f%-2c.%e' - F:/TestPhotos/011.jpg

Other Results:
The file "00929.jpg" still exists in the source folder as: "F:\TestPhotos\00929.jpg"

The file also shows up in the target folder: P:\Original\2012\2012_06_28\00929.jpg


# ------------------------------------------------------
# F:\exifTool\CopyOriginals-2.arg -- Uses -directory<P:\Original/${DateTime2}
# ------------------------------------------------------
# Move Original Files
-P
-o
.
-d
%Y/%Y_%m_%d/
-directory<P:\Original/${DateTime2}
-filename<%f%-2c.%e
-Execute
"F:\TestPhotos"
# --------------------------------------------


exiftool -config "F:\exifTool\.Exiftool_config" -@ "F:\exifTool\CopyOriginals-2.arg" -common_args -r -ext jpg "F:\TestPhotos"

Results:
Error: Error creating file: P:/Original/2012:06:28 08:59:07/00929.jpg - F:/TestPhotos/00929.jpg

Error creating directory P:/Original/2001:01:09 12:55:12
Error: Error creating file: P:/Original/2001:01:09 12:55:12/011.jpg - F:/TestPhotos/011.jpg

# --------------------------------------------

Here are the Custom Composite Tags I added to the "F:\exifTool\.Exiftool_config" config file

I am not a Perl programmer but tried my best. Suggestions for improvements are welcome.

The following Composite Tags do work.

        # **** ADD ADDITIONAL COMPOSITE TAG DEFINITIONS HERE ****
        DateTime2 => {
            Desire => {
            0 => 'DateTimeOriginal',
            1 => 'CreateDate',
            2 => 'ModifyDate',
            3 => 'FileModifyDate',
            },
            ValueConv => q{
            my $year;
            my ($badDate) = 0;
              if (defined $val[0]) {
              $year = $val[0] =~ /(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})(.*)/ ? "$1" : substr($val[0],0,4);
if ($year eq "0000") {
            $badDate = 1;
} else {
              if (defined $6) {
              return "$1:$2:$3 $4:$5:$6";
        }
        return $val[0]
      }
      }
              if (defined $val[1]) {
              $year = $val[1] =~ /(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})(.*)/ ? "$1" : substr($val[1],0,4);
if ($year eq "0000") {
            $badDate = 1;
} else {
              if (defined $6) {
              return "$1:$2:$3 $4:$5:$6";
        }
        return $val[0]
      }
        }
              if (defined $val[2]) {
              $year = $val[2] =~ /(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})(.*)/ ? "$1" : substr($val[2],0,4);
if ($year eq "0000") {
            $badDate = 1;
} else {
              if (defined $6) {
              return "$1:$2:$3 $4:$5:$6";
        }
        return $val[0]
      }
        }
              if (defined $val[3]) {
              $year = $val[3] =~ /(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})(.*)/ ? "$1" : substr($val[3],0,4);
if ($year eq "0000") {
            $badDate = 1;
} else {
              if (defined $6) {
              return "$1:$2:$3 $4:$5:$6";
        }
        return $val[0]
      }
        }
        if ($badDate == 1) {
            return '1900:01:01 00:00:00';
            } else {
            return '1901:01:01 00:00:00';
            }
          }
        },
        Year => {
            Require => 'DateTime2',
            ValueConv => '$val=~s/:.*//; $val',
        },

# ------------------------------------------------------



Phil Harvey

To implement the -d date/time formatting option for your Composite tag, you must add this line to the definition:

    PrintConv => '$self->ConvertDateTime($val)',

The only ways to discover this yourself would be to take a look at the source code for some built-in ExifTool date/time tags, or search the forum here for other examples of user-defined date/time tags.

- 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 ($).