ExifTool Forum

ExifTool => Newbies => Topic started by: magarlick on June 11, 2018, 02:10:12 PM

Title: Rename based on date when file already exists
Post by: magarlick on June 11, 2018, 02:10:12 PM
Hi guys

I'm using this command to rename JPGs and their matching XMPs to the data taken:

exiftool "-filename<filemodifydate" "-filename<datetimeoriginal" -d "%Y-%m-%d_%H-%M-%S.%%e" *.jpg *.xmp

I'm getting errors because some of the photos have exactly the same time, so it won't rename them. How can I get around this? Increment the times by a few seconds, say?

Many thanks.
Title: Re: Rename based on date when file already exists
Post by: StarGeek on June 11, 2018, 02:42:16 PM
Take a look at the %c variable (see the docs for -w option (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut)).  This will add a counter number when there's a duplicate name.

So if you change your date option to -d "%Y-%m-%d_%H-%M-%S%%-c.%%e", two files with the same timestamp would end up like this:
2018-06-11_11-39-46.jpg
2018-06-11_11-39-46-1.jpg

Title: Re: Rename based on date when file already exists
Post by: magarlick on June 11, 2018, 04:22:39 PM
Excellent, many thanks.

ANd how can I include a string in the new file name, prefixed at the beginning? Such as

France 2018-08-23_12_24_23.jpg

Cheers.
Title: Re: Rename based on date when file already exists
Post by: Phil Harvey on June 11, 2018, 04:29:35 PM
Is this what you mean?:

-d "France %Y-%m-%d_%H-%M-%S%%-c.%%e"

- Phil
Title: Re: Rename based on date when file already exists
Post by: magarlick on June 12, 2018, 08:33:02 AM
Thank you, Phil.