ExifTool Forum

ExifTool => Newbies => Topic started by: Stephen Marsh on January 01, 2019, 09:29:01 PM

Title: Reset Sequential Numbering for Each Directory Processed?
Post by: Stephen Marsh on January 01, 2019, 09:29:01 PM
A similar thread here:

https://exiftool.org/forum/index.php/topic,9289.msg48005.html#msg48005

However I wish to reset the increment number on each folder processed...

Before:

DIR
   SubDir-A
      batch-A1.png
      batch-A2.png
      batch-A3.png
   SubDir-B
      batch-B1.png
      batch-B2.png
      batch-B3.png

After:

DIR
   SubDir-A
      batch-A1-001.png
      batch-A2-002.png
      batch-A3-003.png
   SubDir-B
      batch-B1-001.png
      batch-B2-002.png
      batch-B3-003.png

What I can currently do is the following, which is undesired:

DIR
   SubDir-A
      batch-A1-001.png
      batch-A2-002.png
      batch-A3-003.png
   SubDir-B
      batch-B1-004.png
      batch-B2-005.png
      batch-B3-006.png

exiftool '-filename=%f_%.3nC.%e' -r 'DIR'

Is this possible?
Title: Re: Reset Sequential Numbering for Each Directory Processed?
Post by: Phil Harvey on January 02, 2019, 07:46:12 AM
Currently there is no way to do this.

Adding this option would be easy except that I can't think of a good syntax to use for specifying this.  Doing %-C would make sense (because the "-" is somewhat redundant with %C), but this would break backward compatibility in the case where someone was already using %-C.

- Phil
Title: Re: Reset Sequential Numbering for Each Directory Processed?
Post by: Phil Harvey on January 02, 2019, 08:25:10 AM
I think I'll go ahead and change the meaning of '-' and '+' when used with %C.  Hopefully this won't affect too many people.  Here is the proposed update to the documentation:

            A special feature allows the copy number to be incremented for
            each processed file by using %C (upper case) instead of %c.  This
            allows a sequential number to be added to output file names, even
            if the names are different.  For %C, a copy number of zero is not
            omitted as it is with %c.  A leading '-' causes the number to be
            reset at the start of each new directory, and '+' has no effect.

            [...]

This will be implemented in ExifTool 11.24 unless I hear an objection.

- Phil
Title: Re: Reset Sequential Numbering for Each Directory Processed?
Post by: Stephen Marsh on January 03, 2019, 12:27:47 AM
Thanks Phil, I was just curious as it saves working one directory at a time. It is surprising that the coding is simple enough for you to do, but working out the appropriate syntax is harder for you, I guess there are conflicts with other arguments and possibly a lack of free characters for the argument? If you are happy enough to make this change then I'm sure it will be useful to many.
Title: Re: Reset Sequential Numbering for Each Directory Processed?
Post by: Stephen Marsh on July 14, 2023, 12:18:50 AM
Thank you Phil! ... A very late follow-up!

The following works fine:

exiftool '-filename=%f_%-C.%e' -r DIR
However, the syntax for adding in zero padding before the incremental number is killing me (yes I have read the updated POD info)!
Title: Re: Reset Sequential Numbering for Each Directory Processed?
Post by: StarGeek on July 14, 2023, 03:40:15 PM
Quote from: Stephen Marsh on July 14, 2023, 12:18:50 AMHowever, the syntax for adding in zero padding before the incremental number is killing me (yes I have read the updated POD info)!

From the docs

QuoteFor %C, a copy number of zero is not omitted as it is with %c.
<snip>
The number before the decimal place gives the starting index, the number after the decimal place gives the field width.

C:\>exiftool -G1 -a -s -filename Y:\!temp\ddd
======== Y:/!temp/ddd/Test0.jpg
[System]        FileName                        : Test0.jpg
======== Y:/!temp/ddd/Test1.jpg
[System]        FileName                        : Test1.jpg
======== Y:/!temp/ddd/Test2.jpg
[System]        FileName                        : Test2.jpg
======== Y:/!temp/ddd/Test3.jpg
[System]        FileName                        : Test3.jpg
======== Y:/!temp/ddd/Test4.jpg
[System]        FileName                        : Test4.jpg
======== Y:/!temp/ddd/Test5.jpg
[System]        FileName                        : Test5.jpg
======== Y:/!temp/ddd/Test6.jpg
[System]        FileName                        : Test6.jpg
    1 directories scanned
    7 image files read

C:\>exiftool -G1 -a -s -Filename=Test%-.3C.%e Y:\!temp\ddd
    1 directories scanned
    7 image files updated

C:\>exiftool -G1 -a -s -filename Y:\!temp\ddd
======== Y:/!temp/ddd/Test000.jpg
[System]        FileName                        : Test000.jpg
======== Y:/!temp/ddd/Test001.jpg
[System]        FileName                        : Test001.jpg
======== Y:/!temp/ddd/Test002.jpg
[System]        FileName                        : Test002.jpg
======== Y:/!temp/ddd/Test003.jpg
[System]        FileName                        : Test003.jpg
======== Y:/!temp/ddd/Test004.jpg
[System]        FileName                        : Test004.jpg
======== Y:/!temp/ddd/Test005.jpg
[System]        FileName                        : Test005.jpg
======== Y:/!temp/ddd/Test006.jpg
[System]        FileName                        : Test006.jpg
    1 directories scanned
    7 image files read
Title: Re: Reset Sequential Numbering for Each Directory Processed?
Post by: Stephen Marsh on July 14, 2023, 08:47:12 PM
Thank you StarGeek, your replies are always helpful and insightful.

OK, incremental progress (no pun intended).

The original directory/sub-dir and files:


dir
  sub-dir-A
      batch-A1.png
      batch-A2.png
      batch-A3.png
  sub-dir-B
      batch-B1.png
      batch-B2.png
      batch-B3.png


After running this command:

exiftool -Filename=%f_%-1.3C.%e -r dir

I get this:


dir
  sub-dir-A
      batch-A1_003.png
      batch-A2_001.png
      batch-A3_002.png
  sub-dir-B
      batch-B1_001.png
      batch-B2_002.png
      batch-B3_003.png


sub-dir-B has been processed in the correct, expected alpha-numeric order (B1 = 001)...

sub-dir-A has processed the second alpha-numeric sorting file first (A2 = 001).

This is on a Mac.


EDIT:

Adding -fileOrder is what I was missing, I finally got there after a number of failed attempts!

exiftool -fileOrder Filename -Filename=%f_%-1.3C.%e -r  dir


So, thank you Phil and StarGeek!

Title: Re: Reset Sequential Numbering for Each Directory Processed?
Post by: StarGeek on July 14, 2023, 09:08:24 PM
I'm not sure why it isn't sorting the files for you to start with, but on my system, I use Stablebit Drive Pool which treats multiple drives as a single one.  I always have to use -fileorder filename because the order in which the drive pool returns the file list is based upon the underlying drive locations, i.e. returns all the files on drive one, then drive two, etc.