How do I use milliseconds when renaming files?

Started by brenton, July 14, 2010, 11:36:44 AM

Previous topic - Next topic

brenton

I have tried %F, but that seems to use the date and not milliseconds.

Phil Harvey

#1
Milliseconds of what?  The -d option does not format fractional seconds, but if you have a tag available you can do something like this:

exiftool -d %Y%m%d%H%M%S "-filename<${datetimeoriginal}${subsectimeoriginal}0.%e" FILE

Normally SubSecTimeOriginal gives 2 decimal places, so I have added a zero to make this milliseconds.

Your mileage may vary.

- Phil

P.S. Note: Use single quotes instead of double quotes in this command if you are on Mac or Linux.
...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 ($).

brenton

What happens if you are renaming files and several files are taken within the same second but milliseconds apart?

Phil Harvey

If you use the subseconds to rename the file, you won't have a problem.  But if these aren't available you can add %c to the filename format string.  This will add a number to make the filename unique.  Usually I use %-c to add a dash before the number when I do this myself, but there are various other possibilities.  See the -w option documentation for details.

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

brenton

When I run "exiftool myimage.jpg", I get a bunch of info including:

Create Date : 2010:07:27 20:40:41.63

I just want to use the "63" part of the create date.

I get all kinds of errors when I run the command from the earlier message.

brenton



Here is my command and the output.  It is now saying that nothing changed in file?  How do I force it to rename the file?

exiftool -v -ext mov -ext thm -ext avi -ext jpg "-Filename<${datetimeoriginal}${subsectimeoriginal}0.%e" -d %Y%m%d_%H%M%S ./Test/.

======== ./Test/./test.JPG
Setting new values from ./Test/./test.JPG
Nothing changed in ./Test/./test.JPG
    1 directories scanned
    0 image files updated
    1 image files unchanged


[Process completed]


brenton

I guess, more specifically, what does it say that it is unchanged?  Obviously "test.jpg" is not the same as "20100727_20404163.jpg"

Phil Harvey

Sorry, I thought I responded to this.

You are displaying CreateDate but using DateTimeOriginal to rename the files.

You should be able to use SubSecCreateDate if CreateDate contains sub-seconds (the CreateDate you are looking at is likely the Composite:CreateDate -- see the Composite tag name documentation for details.

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

brenton

#9
I am still getting this message:


Setting new values from ./Test/./test.JPG
Nothing changed in ./Test/./test.JPG
   1 directories scanned
   0 image files updated
   1 image files unchanged



This is the command I am using:

exiftool -v -ext mov -ext thm -ext avi -ext jpg "-Filename<${datetimeoriginal}${SubSecCreateDate}0.%e" -d %Y%m%d_%H%M%S ./Test/.

Can you clarify what the (error?) message of "Nothing change" means?  I am not sure what exiftool thinks has not changed?  Can you force it to work?

If we can get it forced to work, does the above command look correct now?  Thanks!!


p.s.  I think some of the problem is that the Mac OS doesn't seem to like the ${} around the tags.  Is there another way of combining tags next to each other without the ${} or is there a mac specific way of doing this?  Thanks again!

Phil Harvey

ExifTool says "nothing changed" when everything is the same as before you ran the command.

On OS X, you must use single quotes (') not double quotes (") around any argument containing a '$'.  This could be your problem.

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

techraf

Phil, sorry for bringing up old topic, but I think my question belongs here...

For a long time I used the ${subsectimeoriginal}0 to rename files created by Nikon with 2-digit subsecond.

Now with GS6 I have also files with 3-digit subsecond - which do not need "hardcoded" 0. Is it possible to rename files of both types in one pass?

Phil Harvey

#12
There is a new feature which didn't exist back in 2010 that makes this easy.  There are numerous ways to do this with the new advanced formatting expression feature.  Here is one:

${subsectimeoriginal;$_.=0 x(3-length)}

(the Perl "x" operator replicates a string ("0" in this case) the specified number of times)

- Phil

Edit: Simplified expression by removing argument for "length" (it assumes "$_" if no argument given).  Also removed unnecessary spaces (the remaining space is necessary otherwise "0x" would be interpreted as the start of a hexadecimal number).
...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 ($).

techraf

Thank you very much, Phil. Works perfectly.

Uwe

Hello,
regarding: ${subsectimeoriginal;$_.=0 x(3-length)}.
My question is: is it possible to have leading zeros for the tag SubSecTimeOriginal?
E.g. 2 files, one with the tag SubSecTimeOriginal=8 and the other file with the tag SubSecTimeOriginal=01 (both are DNG files taken with Canon 5DMKIII) will be renamed to:
YYYMMDD-HHMMSS-010.ext
YYYMMDD-HHMMSS-800.ext
In this case the value is wrong 010<>001ms 800<>008ms and also the sort.
Regards, Uwe