Main Menu

Copy number style

Started by lei, October 01, 2022, 11:29:31 AM

Previous topic - Next topic

lei

Dear Experts,

When renaming files, how can I use the Windows style? That is, the first copy doesn't have anything, the second copy has (2), and the third copy has (3), etc..

Thanks in advance!

StarGeek

I can't see a way to do exactly that. The %c copy number variable doesn't have an option for conditionally including extra characters beyond a dash or underscore.  You could use
exiftool -Filename="%f (%nc).%e" /path/to/files/

But the first file would have " ()" in it.  You could then use a second command to remove the empty parentheses.
exiftool -fast3 -if "$Filename=~/ \(\)/" "-Filename<${Filename;s/ \(\)//}" /path/to/files/

Example:
C:\>exiftool -p "$Filename" Y:\!temp\ccc\a
A.Jpg
B.Jpg
C.Jpg
D.Jpg
E.jpg
    1 directories scanned
    5 image files read

C:\>exiftool -Filename="test (%nc).%e" Y:\!temp\ccc\a
    1 directories scanned
    5 image files updated

C:\>exiftool -p "$Filename" Y:\!temp\ccc\a
test ().Jpg
test (2).Jpg
test (3).Jpg
test (4).Jpg
test (5).jpg
    1 directories scanned
    5 image files read

C:\>exiftool -fast3 -if "$Filename=~/ \(\)/" "-Filename<${Filename;s/ \(\)//}" Y:\!temp\ccc\a
    1 directories scanned
    4 files failed condition
    1 image files updated
    0 image files read

C:\>exiftool -p "$Filename" Y:\!temp\ccc\a
test (2).Jpg
test (3).Jpg
test (4).Jpg
test (5).jpg
test.Jpg
    1 directories scanned
    5 image files read
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

lei

Looks like this is the only solution. Thanks StarGeek! Really appreciate it.