ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: kr0ntab on January 11, 2025, 08:01:01 PM

Title: Challenge with file renaming and dynamic counters to avoid duplicates
Post by: kr0ntab on January 11, 2025, 08:01:01 PM
Hi there... I'm running into a problem and feel like I'm overlooking something obvious. When using dynamic counters for identical file names, I get one file with double periods before the extension.

Objective:

Here's the set of files I'm working on.

ls -1 example*.jpg                                                               
example_1.jpg
example_2.jpg
example_3.jpg
example_4.jpg
example_5.jpg
example_6.jpg

Tags are as follows:
exiftool -DateTimeOriginal example*.jpg
======== example_1.jpg
Date/Time Original              : 2017:06:05 13:00:35
======== example_2.jpg
Date/Time Original              : 2017:06:05 13:00:35
======== example_3.jpg
Date/Time Original              : 2017:06:05 13:00:35
======== example_4.jpg
Date/Time Original              : 2017:06:05 13:00:35
======== example_5.jpg
Date/Time Original              : 2017:06:05 13:00:35
======== example_6.jpg
Date/Time Original              : 2017:06:05 13:00:35
    6 image files read

My exiftool syntax to rename the files is as follows:

exiftool -d "%Y-%m-%d_%H-%M-%S.%%03c.%%le" "-FileName<DateTimeOriginal" example*.jpg
    6 image files updated

And here you can see that my first file has a period added before the extension in the first file.

ls -1 *.jpg                                                                                             
2017-06-05_13-00-35..jpg
2017-06-05_13-00-35.001.jpg
2017-06-05_13-00-35.002.jpg
2017-06-05_13-00-35.003.jpg
2017-06-05_13-00-35.004.jpg
2017-06-05_13-00-35.005.jpg

Any ideas would be very much appreciated.
Title: Re: Challenge with file renaming and dynamic counters to avoid duplicates
Post by: StarGeek on January 11, 2025, 10:06:34 PM
The options for a leading separator for the %c variable are either a minus sign, which is indicated with %-c or an underscore, which is %+c. See the Advanced features section of the -w (-TextOut) option (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut) for details.

Anything else would require an additional rename command to remove/change characters or a more complex rename using the FileSequence
Title: Re: Challenge with file renaming and dynamic counters to avoid duplicates
Post by: kr0ntab on January 11, 2025, 11:53:13 PM
Ah, okay... I was heading down the path of a post-process rename job, though was hoping there would be some sort of way to specify the leading separator.

This was most helpful. Thank you!