Renaming files with subsecs.

Started by neebah, July 30, 2017, 08:15:28 PM

Previous topic - Next topic

neebah

I would like to rename my files as follows
Year-Month-Day-HourMinuteSecond-SubSec
2017-07-30-123007-037

If no subseconds I would like to have ### instead. 

So far I have this for everything but the subseconds. 

-d %Y-%m-%d-%H%M%S-.%%e "-testname<DateTimeOriginal"


Phil Harvey

You want literally "###" ?

If so, this should do it:

exiftool -d %Y-%m-%d-%H%M%S- "-testname<${DateTimeOriginal}-###.%e"  "-testname<${DateTimeOriginal}${subsectimeoriginal;$_=substr($_.'000',0,3)}.%e" DIR

Some trickery was necessary to be sure SubSecTimeOriginal was 3 digits.

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

neebah

Sorry yes I want ###.  That's what I use when the subseconds aren't known.  Is there a way to make it greater than or equal to 3 digits for the subsecs. 

Phil Harvey

For >= 3 digits you could do this:

"-testname<${DateTimeOriginal}${subsectimeoriginal;$_.='0'x(3-length)}.%e"

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