Date Fixing and Renaming (Photos and Videos)

Started by frmike, January 13, 2017, 07:00:13 PM

Previous topic - Next topic

Hayo Baan

You'd need to change the %-c.%e on all lines (5 times).
Hayo Baan – Photography
Web: www.hayobaan.nl

frmike

Big thanks to Hayo!

Here is the script he helped me with getting to do things right.

exiftool -api QuickTimeUTC -P -d '%Y-%m-%d at %H-%M-%S' \
   '-filename<${FileModifyDate;}$#{filename;s/.*(\d{4}\..*)/$1/;}' \
    '-filename<${GPSDateTime;}$#{filename;s/.*(\d{4}\..*)/$1/;}' \
    '-filename<${MediaCreateDate;}$#{filename;s/.*(\d{4}\..*)/$1/;}' \
    '-filename<${DateTimeOriginal;}$#{filename;s/.*(\d{4}\..*)/$1/;}' \
    '-filename<${CreationDate;}$#{filename;s/.*(\d{4}\..*)/$1/;}' \
    "$1"


Works for photos and movies.
Beginning file name looks like this 2017-01-09_16-40-26_IMG_6714.jpg
Ending file name looks like this 2017-01-09_16-40-26_IMG_6714 - 3024 x 4032.jpg
Modified Date in Finder checks out to match the above timestamp
Last Opened Date in Finder checks out to match the above timestamp

The only possible change I would recommend (but it's more for visual aide) is to have the words "at" between the date and time.

2017-01-09 at 16-40-26_IMG_6714 - 3024 x 4032

But, I am content.  :) Thank you everyone

Phil Harvey

OK, I'm stumped.  What is the "#" symbol for in "$#{filename...", and why does it work?  (As far as I know, that is an invalid syntax.)

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

Hayo Baan

Quote from: Phil Harvey on January 16, 2017, 07:09:57 AM
OK, I'm stumped.  What is the "#" symbol for in "$#{filename...", and why does it work?  (As far as I know, that is an invalid syntax.

Oops, the # is meant to go before the $ (and can be replaced by anything you like as separator)

And actually looking at the output, it didn't work with the # at the wrong position; the filenames were NOT changed from their original (hence also the missing at in the date).
Hayo Baan – Photography
Web: www.hayobaan.nl

frmike

Yes, everything looks good now with the corrections!
Thank you so much!

koppor

Some other hint posted one year later.

See https://exiftool.org/forum/index.php?topic=9647.msg50095#msg50095 for details.

Quick excerpt:

With a custom config, you can use MyDate as date:

exiftool -config my.config ... -filename<MyDate


%Image::ExifTool::UserDefined = (
    'Image::ExifTool::Composite' => {
        MyDate => {
            Desire => {
                0 => 'DateTimeOriginal',
                1 => 'CreateDate',
                2 => 'FileModifyDate',
            },
            ValueConv => '$val[0] || $val[1] || $val[2]',
            PrintConv => '$self->ConvertDateTime($val)',
        },
    },
);
1; #end