ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: octavo on February 05, 2025, 12:33:37 PM

Title: Using the plus sign (+) in the filename rename command
Post by: octavo on February 05, 2025, 12:33:37 PM
Hello,

I have the following command to rename a file to the date/time of it's DateTimeOriginal:

exiftool -d '%Y%m%d-%H%M%S%+.c.%%e' '-filename<DateTimeOriginal' .
This works great, but I want to actually have a plus sign in the filename, not an underscore, which is what the plus sign is replaced with. Is it possible to escape this somehow please?
Title: Re: Using the plus sign (+) in the filename rename command
Post by: Phil Harvey on February 05, 2025, 12:38:22 PM
This is easy since you always want the number in the name:

-d '%Y%m%d-%H%M%S+%.c.%%e'

The %-c and %+c are only useful if you don't want the number when there is only one file with that name.

- Phil
Title: Re: Using the plus sign (+) in the filename rename command
Post by: octavo on February 05, 2025, 12:58:03 PM
Sorry Phil, I think in my testing of different commands, I pasted the wrong one in my post.

Ideally, I'd like the first file it encounters to not have a modifier, but all subsequent ones to have +1, +2 etc.

The command I came up with so far is:

exiftool -d '%Y%m%d-%H%M%S%%+c.%%e' '-filename<DateTimeOriginal' .
However, this is the code that outputs a underscore instead of a +.

If I follow your suggestion on this and move the plus sign before the percentage, it leaves the first file with a plus sign then the extension, e.g. 20250205-180000+.jpg
Title: Re: Using the plus sign (+) in the filename rename command
Post by: StarGeek on February 05, 2025, 01:26:57 PM
There are only two options for the %c, either a minus sign (%-c) or an underscore (%+c).

You'll have to run the command with one of these first, then run a second command to change to a plus sign.

This should change an Underscore### into Plus###. Test it out first, as I have not done so.
exiftool -if "$BaseName=~/_\d+$$/" "-Filename<Basename;s/_(\d+)$/+$1/}.%e" /path/to/files/

Title: Re: Using the plus sign (+) in the filename rename command
Post by: octavo on February 05, 2025, 02:03:41 PM
Thanks both :)