exiftool -d duplicate filename

Started by jeoxif, May 17, 2013, 01:13:10 PM

Previous topic - Next topic

jeoxif

So we took pictures today and I put all pictures in same folder. I like it that way, as a slideshow then will cover everything.
But I discovered that exiftool had a problem with 3 files that were taken almost simultaneously.

e.g.

C:\Pics>exiftool -d %Y-%m-%d/image-%Hh%Mm%S.%%e "-filename<datetimeoriginal" .
Error: '2013-05-17/image-12h38m56.JPG' already exists - ./DSCF3025.JPG

So my wifes camera and my camera took pictures the very same second.

Is there a way to make make exiftool create a second filename? e.g. 2013-05-17/image-12h38m56_2.JPG  or similar?


Phil Harvey

Yes.  You can use %c in the filename string to add a copy number if necessary (starting from 1 by default).  %+c adds a leading underline.

This is all detailed in the application documentation.

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

jeoxif

exiftool -d %Y-%m-%d/image-%Hh%Mm%S%c.%%e "-filename<datetimeoriginal" .
wont work..

Phil Harvey

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

jeoxif

Excellent! Thank you for an excellent utility!

Phil Harvey

For reference, I have prepared a page describing this feature of exiftool here.

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

bes1002t

Sorry to revive this old topic, but I have a very similar problem, just a little bit more complex.

I'm shooting raw and jpg with a Sony camera. So, there is always a matching pair of photos, one jpg and one raw with the exact same image. So far, for renaming my files I also used the %c placeholder. Problem is, after renaming filename-1.jpg does not match with filename-1.raw, but with filename-3.raw.

I can imagine that Exiftool simply uses the integer randomly and not ordered.


How to fix:
My idea how to fix this is, using the shutter count exif information (if it exists) from the photo and include it into the file name instead of the %c option.

My question:
Is there a similar placeholder like %c for the shuttercount?

Phil Harvey

Quote from: bes1002t on August 24, 2024, 04:36:24 PMI can imagine that Exiftool simply uses the integer randomly and not ordered.

ExifTool uses sequential integers in the order the files are processed.  If using wildcards or processing a whole directory, the files are often supplied in alphabetical order by the system, but not always.  You can use the -fileorder option to order the processing however you want.

I use ShutterCount myself in my file names.

If renaming via CreateDate for example, you can do this:

exiftool -d SOME_DATE_FORMAT "-filename<${createdate}_${shuttercount}.%e" DIR

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

bes1002t

Thanks for the quick answer and the two solutions to my problem!

Just out of curiosity, is there a way to add the shuttercount only if there are two or more files with the same name?
My current command looks the following: exiftool -d %Y-%m-%d_%H%M%S%%-c.%%e '-filename<${datetimeoriginal}' *.*

Phil Harvey

Quote from: bes1002t on August 24, 2024, 05:02:47 PMJust out of curiosity, is there a way to add the shuttercount only if there are two or more files with the same name?

This would take a second command.  The first to rename without the ShutterCount or %c, then a second to rename the files with ShutterCount that weren't renamed before due to name conflicts.

- 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

I haven't tested it, but your commands would be something like this

First, remove the %%c.  Also, the dollar sign and braces aren't needed for a direct single tag to tag copy without any static string (see Common Mistake #5b) and a simple dot should be used for the current directory, as wildcard may give unexpected results depending upon the OS (see Common Mistake #2). I also suggest moving the files in the first pass to a different directory, as otherwise they would get caught up in the second command. For example, this will move the files in the first pass to a subdirectory called "Renamed".
exiftool -d %%dRenamed/%Y-%m-%d_%H%M%S.%%e '-filename<datetimeoriginal' .

Then for the second pass, because two tags will now be used in the file name, the dollar signs need to be brought back. Important, make sure that ShutterCount actually exists in your files. Different camera companies have different names for this and some don't have it at all
exiftool -d %Y-%m-%d_%H%M%S '-filename<%dRenamed/${DateTimeOriginal}_$ShutterCount.%e' .

Braces are needed around DateTimeOriginal because it is followed by an underscore (see the -p (-printFormat) option, first paragraph) but ShutterCount does not because the dot is not one of the reserved characters.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Martin B.

Quote from: bes1002t on August 24, 2024, 05:02:47 PMJust out of curiosity, is there a way to add the shuttercount only if there are two or more files with the same name?

Hi,

I wrote a Perl script to do this without renaming files twice, and do other things as well. It only works on Windows, mainly to ignore differences between upper/lower case in file names, but I'd be happy to collaborate to make it work on other operating systems. Here's the documentation: sorp-manual.html

Send me a message if you want a copy.

- Martin

bes1002t