I tried to rename MPG files

Started by modelmark, December 08, 2013, 05:24:13 PM

Previous topic - Next topic

modelmark

I'm at it about 6 hours, starting to think that either I'm stupid or exiftool is not the right tool for the job

I think I wanted something very simple. A directory with files and rename them
<year><month><date>_<hour><minute><Second>_<duration_h>h<duration_m>m<duration_s>s

this one gets me the files with the date
exiftool -ext MPG -P -d "%Y-%m-%d %H.%M.%S" "-filename<${FileCreateDate}.%e" dir
this one with duration, but unfortunately followed with   <approximate>
exiftool -ext MPG -P -d "%hh%mm%ss" "-filename<${Duration;}.%e" dir

but hwo do I get one with both in the file name?

Phil Harvey

#1
Generally, it is done like this:

exiftool -d "%Y-%m-%d %H.%M.%S" "-filename<${FileCreateDate}_${Duration}.%e" ...

But the problem is that you want Duration to be formatted differently.  The -d option doesn't apply to Duration.  This is an advanced feature, but it can be done like this:

${duration#;$_=sprintf('%.2d%.2d%.2d',$_/3600,($_/60)%60,$_%60)}

so the whole command would look like this:

exiftool -d "%Y-%m-%d %H.%M.%S" "-filename<${FileCreateDate}_${duration#;$_=sprintf('%.2d%.2d%.2d',$_/3600,($_/60)%60,$_%60)}.%e" ...

- Phil

Edit: Fixed incorrect bracket in example command.
...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 ($).

modelmark

Wauw, thanks, would not have figured that one out, although I understand it enough to make small changes. Thanks again.

modelmark

#3
Strange I try to repeat the same trick with a new batch of files and it gives me
Warning: No writable tags set from 20140323.151201.MPG
    0 image files updated
    1 image files unchanged

quotes need changing
exiftool -ext MPG -d '%Y%m%d_%H%M%S' '-filename<${FileModifyDate}_${duration#;$_=sprintf("%dm%2ds",($_/60)%60, $_%60)}.%e' filename.MPG

Phil Harvey

You need the double quotes on Windows, or single quotes on Mac/Linux.

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