ExifTool Forum

ExifTool => Newbies => Topic started by: Tom Cunningham on March 02, 2015, 06:30:43 PM

Title: Append date to filename
Post by: Tom Cunningham on March 02, 2015, 06:30:43 PM
Still a newb.  :P  I'm trying to append the DateTimeOriginal to a directory of filenames in the form IMG_NNNN.jpg.  I've tried this in Cygwin:

    exiftool -d %Y-%m-%d-%H%M_%%f.%e "-filename<datetimeoriginal" .

which creates a directory "%Y-%m-" containing a file "-%H%M_%IMG_NNNN.jpg", not at all what I was looking for.  I don't want any new directories, just a new filename of the form:

    YYYY-MM-DD-HHMM_IMG_NNNN.jpg

for each file in the directory.  Can someone throw me a bone here?  Thanks.

UPDATE:

Never mind.  I get what I want with:

    exiftool '-filename <${DateTimeOriginal}_%f.%e' -d %Y%m%d-%H%M .

Phil, you can remove this post if you want.

Title: Re: Append date to filename
Post by: Phil Harvey on March 02, 2015, 08:05:15 PM
I'm glad you figured it out.  Your first command was very close:

Quote from: Tom Cunningham on March 02, 2015, 06:30:43 PM
    exiftool -d %Y-%m-%d-%H%M_%%f.%e "-filename<datetimeoriginal" .

But you forgot to escape the "%e" with an extra "%".  It should have been:

exiftool -d %Y-%m-%d-%H%M_%%f.%%e "-filename<datetimeoriginal" .[/quote]

Quotewhich creates a directory "%Y-%m-" containing a file "-%H%M_%IMG_NNNN.jpg",

This I don't understand, unless you put an extra "%" on the "%d" ("%%d" would give you the directory "./" in the result instead of the day of the month).

- Phil
Title: Re: Append date to filename
Post by: chris.b on March 06, 2015, 04:26:52 PM
phil,

similar problem here in vienna/austria/europe/earth/solsystem/alpha quadrant/milkyway/universe4711/warehouse8/rack4/box2: exiftool 9.88 @ mac os x 10.10.2

exiftool '-FileName<$CreateDate $FileName ' -d %Y-%m-%d_%H.%M.%S /PIX/ZZZ

i.e. IMG_0294.JPG >> 2013-06-26_11.05.43 IMG_0294.JPG

does what i was expecting... but the document type has changed from "jpeg-image" to "textedit.app-document"... !?!?!?
the file's name is "IMG_0294"; type (extension) is "JPG" – (why) do i have to consider the extension, too?

kind regards
©hris, confused...  ;)
Title: Re: Append date to filename
Post by: Phil Harvey on March 07, 2015, 07:46:36 AM
Hi Chris,

Quote from: chris.b on March 06, 2015, 04:26:52 PM
does what i was expecting... but the document type has changed from "jpeg-image" to "textedit.app-document"... !?!?!?

The problem is the extra space you have after $FileName which is adding a space after the extension.

- Phil
Title: Re: Append date to filename
Post by: chris.b on March 07, 2015, 10:39:53 AM
well, you are right!
so, 'filename' = <file's name> + <.> + <ext>

thx & regards
©hris
Title: Re: Append date to filename
Post by: Suzanne on May 06, 2015, 12:33:36 PM
Thank you to the first poster who put their solution, which was this:

exiftool '-filename <${DateTimeOriginal}_%f.%e' -d %Y%m%d-%H%M   (add a space)

drag in image (add a return)

exiftool immediately changed the date.  I imported the revised photo into the Photos app and the photo was located correctly chronologically.  Success!!

I need a variation to work with a video file. 

When I just type in:

exiftool    (space)

drag in the video    (return)

exiftool works wonderfully and the original creation date is provided:

Creation Date (und-US)          : 2014:11:12 12:29:01-05:00

However, if I copy/paste the longer string (space) (drag) (return), I get this:

Warning: No writable tags set from /Users/Suzanne/Desktop/Test Reimport/IMG_4436.m4v
    0 image files updated
    1 image files unchanged

Title: Re: Append date to filename
Post by: Phil Harvey on May 06, 2015, 12:38:03 PM
Hi Suzanne,

You need to change DateTimeOriginal in your command to the name of any existing date/time tag in the image.  Use this command to see what date/time tags are available:

exiftool -s -time:all (and a space, then drag,drop and RETURN)

Apparently CreationDate is available, but it is a localized version so you should get its exact name from the command above if you want to use it.

- Phil
Title: Re: Append date to filename
Post by: Suzanne on May 06, 2015, 03:32:12 PM
I used the new command to get the right term and changed the command line to:

exiftool '-filename <${CreationDate}_%f.%e' -d %Y%m%d-%H%M   

This did change the name of the file! 

Unfortunately, when imported back into Photos app, whereas the photo located in the right date, the video located in today's date.  Still, that is a small problem, because I can use the Adjust Date and Time feature and then the video moves to the right date.  At least I can see what the date is!  And being able to drag more than one image and have them all change in a blink is brilliant!

Thank you so much and thanks to Tom for getting me on the right track!