Easy newbie question ;-)

Started by Valith, May 09, 2017, 02:13:05 PM

Previous topic - Next topic

Valith

Hi guys,

I'm pretty new to this great tool and also to command line scripting.
However with some research, reading examples, manuals and trial and error, I managed to get some results I like so far (I like digging into it too).

Context:
The main problem I was trying to tackle, is the fact that iCloud (and former iOS) downloads of video & photo files, did not have the right creation dates. Secondly files had just a name IMG_0567.JPG and IMG_0873.MOV and I thats not easy to sort.

So I created this:
exiftool '-FileModifyDate<TrackCreateDate' '-FileName<${CreateDate}_${Model;}(%f)%-c.%le' -d %Y-%m-%d_%H.%M.%S *

Input example:
IMG_1128.JPG

Output example:
2010-12-31_20.44.31_iPhone 4(IMG_1128).jpg

This works  :D    but...

So now my current issue and question:
Some files do not have a ${Model} to be detected in the EXIF (it's just not there for some files when I run exiftool -csv * > EXIF_before_rename.csv)
).

What I like to do is replace the  ${Model} for a manual input for example "iPhone 4".
Issue: I'm not allowed to use a space (between "iPhone" and "4".. (tried quotes around it and &nbsp, but didn't work out).

Any help with building the right command is highly appreciated.
All other feedback is appreciated too :-)

Note: Possibly two or more directions. Easy one is the right code to use a space. But I know it's also possible to write it in the EXIF when missing. Not sure how to do this. And there might be other solutions that you would pick for me case..

I hope this is the right place on this forum to post this question in, but admins please feel free to move it over to another spot  ;)

Phil Harvey

You could do this to set the model to "iphone 4" if it doesn't exist, otherwise use the existing model:

exiftool '-FileModifyDate<TrackCreateDate#' '-FileName<${CreateDate}_iPhone 4(%f)%-c.%le' '-FileName<${CreateDate}_${Model;}(%f)%-c.%le' -d %Y-%m-%d_%H.%M.%S .

here I have also added "#" to TrackCreateDate to copy the unformatted date/time value.  Your formatting doesn't mess things up right now, but it could if you change it around at all, so this could make the command more future proof.

(and I changed "*" to "." for these reasons.)

Also, why are you using TrackCreateDate for the file time and CreateDate for the file name?

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

Valith

Thanks for your quick and useful reply! Nice to see that you (still) write reply's to these kind of questions, as the author of this great tool. I wasn't expecting that.. Great job.

Quote from: Phil Harvey on May 09, 2017, 03:01:37 PM
You could do this to set the model to "iphone 4" if it doesn't exist, otherwise use the existing model:

Great tip! I'll definitely use that sequence.
I also implemented such a sequence again, in the second part, because I ran into another issue:

Some files (strangely enough) do not have a CreateDate set in EXIF.

So I now have:
exiftool '-FileModifyDate<${FileModifyDate}' '-FileModifyDate<CreateDate#' '-FileName<${FileModifyDate}_iPhone 4(%f)%-c.%le' '-FileName<${CreateDate}_${Model;}(%f)%-c.%le' -d %Y-%m-%d_%H.%M.%S .

Quote from: Phil Harvey on May 09, 2017, 03:01:37 PM
here I have also added "#" to TrackCreateDate to copy the unformatted date/time value.  Your formatting doesn't mess things up right now, but it could if you change it around at all, so this could make the command more future proof.

In my first attempt I got warnings like:
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_0544.JPG
Warning: No writable tags set from ./IMG_0544.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_1125.jpg

Second attempt:
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_0515.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_0516.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_0517.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_0518.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_0519.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_0520.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_0521.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_0522.JPG

I'll try to debug myself, maybe the use of ${FileModifyDate} instead of FileModifyDate#..

Quote from: Phil Harvey on May 09, 2017, 03:01:37 PM
(and I changed "*" to "." for these reasons.)
Great!  :D

Quote from: Phil Harvey on May 09, 2017, 03:01:37 PM
Also, why are you using TrackCreateDate for the file time and CreateDate for the file name?
Don't know why I used this. Maybe because I started with video's and ran into it in the EXIF. Now changed it to CreateDate and when not available I'll use FileModifyDate



Q?: Is it better to use FileModifyDate# then ${FileModifyDate}? (What's the difference?)

Valith

I changed the code again to:

exiftool '-FileModifyDate<FileModifyDate#' '-FileModifyDate<CreateDate#' '-FileName<${FileModifyDate}_iPhone 4(%f)%-c.%le' '-FileName<${CreateDate}_${Model;}(%f)%-c.%le' -d %Y-%m-%d_%H.%M.%S *.JPG

Added *.JPG, because I don't want my screenshots (PNG files) to be included.

And I changed FileModifyDate<${FileModifyDate}' in FileModifyDate<FileModifyDate#', but it didn't solve the warnings:
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - IMG_1072.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - IMG_1073.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - IMG_1074.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - IMG_1075.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - IMG_1076.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - IMG_1077.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - IMG_1078.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - IMG_1079.JPG
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - IMG_1080.JPG


If I leave those # out, I don't have those warnings... ?

exiftool '-FileModifyDate<FileModifyDate' '-FileModifyDate<CreateDate' '-FileName<${FileModifyDate}_iPhone 4(%f)%-c.%le' '-FileName<${CreateDate}_${Model;}(%f)%-c.%le' -d %Y-%m-%d_%H.%M.%S *.JPG

Phil Harvey

Quote from: Valith on May 09, 2017, 04:09:04 PM
Warning: Error parsing time in File:FileModifyDate (PrintConvInv) - ./IMG_0515.JPG

Ah, right.  You must also write the unformatted time: '-filemodifydate#<createdate#'

QuoteQ?: Is it better to use FileModifyDate# then ${FileModifyDate}? (What's the difference?)

See Common mistake 5b.

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

StarGeek

Quote from: Phil Harvey on May 09, 2017, 04:29:14 PM
Quote from: Valith on May 09, 2017, 04:09:04 PM
QuoteQ?: Is it better to use FileModifyDate# then ${FileModifyDate}? (What's the difference?)

See Common mistake 5b.

A bit more info.  Tags can be modified by various options, such as the -d or -api Filter options.  in your case, the -d option changes the format of the FileModifyDate tag.  The hashtag at the end of a tag uses the original unmodified data. It's the same as the -n option, but for a single tag.  You can try a command like exiftool -d %Y-%m-%d_%H.%M.%S -FileModifyDate -FileModifyDate# to see the difference.

C:\>exiftool -d %Y-%m-%d_%H.%M.%S -FileModifyDate -FileModifyDate# X:\!temp\Test3.jpg
File Modification Date/Time     : 2017-05-03_12.30.57
File Modification Date/Time     : 2017:05:03 12:30:57-07:00
* 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).

Phil Harvey

Right.  Stargeek explained the difference of adding a "#", and I explained the difference of adding a "$".

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

nndrom

Hi Phil,

I'm newbie on this wonderful exiftool. I discovered your posts after I needed to recover a lost partition on my usb hdd full of family photos and movies.
Mostly were recovered but with new names making my life terrible as the previous order by date was completely lost.
I have installed in my windows computer the pyexiftoolgui.exe and succeeded to rename all photos (jpg) files. Wonderful exiftool!!!
Now I need to see what can be done with the movie files (mp4, avi, mpg and mts).
Can you please advise which parametrs should I use in the command line of pyexiftoolgui.exe to rename the movie files too?
I've noticed that most of the movies still have the Date/Time Original info available.
Many thanks in advance.
Nick
 

Phil Harvey

Hi Nick,

I'm glad you've found exiftool, but unfortunately I can't help with pyexiftool since I have never tried this utility myself.  What is keeping you from running exiftool directly, rather than through the pyexiftool wrapper?

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

nndrom

I have no problem, except I didn't do it till now.
I have copied exiftool.exe in the windows folder - how and which command should I use.
Sorry for my lack of knowledge.
Nick

Phil Harvey

The command will look something like the command mentioned in the first post of this topic, without the '-FileModifyDate<TrackCreateDate', and using double quotes instead of single quotes (since you are on Windows).  The exact form depends on the form you want for the new file name.

But you will have to add this to your command to process the types of files you want:

-ext mp4 -ext avi -ext mpg -ext mts

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

nndrom

Thank you very much.
I'll try it later this evening.

Should it look like this for my mts files folder?

C:\>exiftool "-FileName<${DateTimeOriginal}_${Model;}(%f)%-c.%le" -ext mts -d %Y-%m-%d_%H.%M.%S * H:\MTS\all

Nick

Phil Harvey

Hi Nick,

Yes, except remove the "*" from the command.

That should work provided your MTS files have DateTimeOriginal and Model information.

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

nndrom

It worked !!! with the following command:
exiftool "-FileName<${DateTimeOriginal}(%f)%-c.%le" -ext mts -d %Y-%m-%d_%H.%M.%S H:\MTS\*.mts

The only problem is that the original date was added to the existing file name!
It looks now like this:
2017-01-17_15.18.41(Found_2821326_2025600).mts

Can I include something in the command to delete the old name (between brackets)?

Thanks!

Nick

Phil Harvey

Hi Nick,

Try this:

exiftool "-FileName<${DateTimeOriginal}%-c.%le" -ext mts -d %Y-%m-%d_%H.%M.%S H:\MTS

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