ExifTool Forum

ExifTool => Newbies => Topic started by: dwlott on April 06, 2022, 06:02:46 PM

Title: Sequence numbering with set number of digits.
Post by: dwlott on April 06, 2022, 06:02:46 PM
Hello,
I am renaming some files.  At the end of the file names, I want to append -0010, -0011, -0012, and so on.
Like -4c, (add a copy).  But with the C option.  I tried -4C, but that starts the sequence a 4, not giving me the 4 digits that I need.
I would like to have both the start number for the sequence, and the number of digits also.  So if I want to start the sequence at 10, the result would be as shown above.
Thank you again for your help. 
Title: Re: Sequence numbering with set number of digits.
Post by: StarGeek on April 06, 2022, 06:13:53 PM
From the docs on the -w (-TextOut) option (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut), where the % tokens are documented
    For %C, ... The number before the decimal place gives the starting index, the number after the decimal place gives the field width

Example, using Testname
C:\>exiftool -Testname=Image-%10.4C.%e Y:\!temp\ccc
'Y:/!temp/ccc/Image-01.jpg' --> 'Y:/!temp/ccc/Image-0010.jpg'
'Y:/!temp/ccc/Image-02.jpg' --> 'Y:/!temp/ccc/Image-0011.jpg'
'Y:/!temp/ccc/Image-03.jpg' --> 'Y:/!temp/ccc/Image-0012.jpg'
'Y:/!temp/ccc/Image-04.jpg' --> 'Y:/!temp/ccc/Image-0013.jpg'
'Y:/!temp/ccc/Image-05.jpg' --> 'Y:/!temp/ccc/Image-0014.jpg'
'Y:/!temp/ccc/Image-06.jpg' --> 'Y:/!temp/ccc/Image-0015.jpg'
'Y:/!temp/ccc/Image-07.jpg' --> 'Y:/!temp/ccc/Image-0016.jpg'
'Y:/!temp/ccc/Image-08.jpg' --> 'Y:/!temp/ccc/Image-0017.jpg'
'Y:/!temp/ccc/Image-09.jpg' --> 'Y:/!temp/ccc/Image-0018.jpg'
'Y:/!temp/ccc/Image-10.jpg' --> 'Y:/!temp/ccc/Image-0019.jpg'
'Y:/!temp/ccc/Image-11.jpg' --> 'Y:/!temp/ccc/Image-0020.jpg'
'Y:/!temp/ccc/Image-12.jpg' --> 'Y:/!temp/ccc/Image-0021.jpg'
'Y:/!temp/ccc/Image-13.jpg' --> 'Y:/!temp/ccc/Image-0022.jpg'
'Y:/!temp/ccc/Image-14.jpg' --> 'Y:/!temp/ccc/Image-0023.jpg'
'Y:/!temp/ccc/Image-15.jpg' --> 'Y:/!temp/ccc/Image-0024.jpg'
'Y:/!temp/ccc/Image-16.jpg' --> 'Y:/!temp/ccc/Image-0025.jpg'
    1 directories scanned
    0 image files updated
   16 image files unchanged
Title: Re: Sequence numbering with set number of digits.
Post by: dwlott on April 06, 2022, 09:54:53 PM
Thank you, that is the answer that I needed.
Title: Re: Sequence numbering with set number of digits.
Post by: dwlott on April 07, 2022, 12:08:13 AM
Quote from: StarGeek on April 06, 2022, 06:13:53 PM
From the docs on the -w (-TextOut) option (https://exiftool.org/exiftool_pod.html#w-EXT-or-FMT--textOut), where the % tokens are documented
    For %C, ... The number before the decimal place gives the starting index, the number after the decimal place gives the field width

Is there a way to increment only when a file is actually renamed?
This is almost working perfectly for me: 
e:\exiftool\exiftool -r "-TestName<e:\exiftool\myTargetFolder\${IPTC:City;}-${IPTC:Province-State;}-%1.5C.%e" "e:\exiftool\mySourceFolder" > "e:\exiftool\out.txt"

The count is skipping 00001, 00003, 00008, 00010, 00017... when there are files that are not renamed because they don't have the tags.
Not all the files qualify to be moved because not all of the files have city and state tags. 
Title: Re: Sequence numbering with set number of digits.
Post by: Phil Harvey on April 07, 2022, 10:17:22 AM
To do this you could avoid processing the offending files by adding a -if option:

  -if "$IPTC:City and $IPTC:Province-State"

- Phil
Title: Re: Sequence numbering with set number of digits.
Post by: dwlott on April 07, 2022, 03:52:56 PM
Thank you, Phil,
The "if" solution is working great.