ExifTool Forum

ExifTool => Bug Reports / Feature Requests => Topic started by: taob on July 08, 2019, 03:37:16 AM

Title: Specify starting number/letter for %c
Post by: taob on July 08, 2019, 03:37:16 AM
I poked around a bit and couldn't find any mention of this before. Is it possible to specify the starting number or letter for %c?

I'm using exiftool to replicate the functionality of an older, deprecated tool used to download images from a memory card. When it encounters a duplicate destination filename, it appends a letter. The only difference is the other piece of software starts with 'a', whereas exiftool starts with 'b'. I thought I would be clever by specifying '%lnc', but alas that simply translates to a literal %lnc in the filename.  ;D
Title: Re: Specify starting number/letter for %c
Post by: Phil Harvey on July 08, 2019, 08:48:52 AM
Try this: %-.lc

            By default, the copy number
            is omitted from the first file of a given name, but this can be
            changed by adding a decimal point to the modifier.

            [...]

                -w H%-lc.txt      # H.txt, H-b.txt, H-c.txt ...

            [...]

            All format codes may be modified by 'l' or 'u' to specify lower or
            upper case respectively (ie. %le for a lower case file extension).
            When used to modify %c or %C, the numbers are changed to an
            alphabetical base (see example H above).

- Phil
Title: Re: Specify starting number/letter for %c
Post by: Hayo Baan on July 08, 2019, 09:47:01 AM
Hi Phil,

The way I understand the question is that he wants file.ext, file-a.ext, file-b.ext, etc. Not file-a.ext, file-b.ext, file-c.ext. So no extension on the first, but thereafter starting with a, not b.
Title: Re: Specify starting number/letter for %c
Post by: Phil Harvey on July 08, 2019, 10:28:16 AM
Ah, ok.  Right.  Then I understand the %lnc suggestion now.  This currently can't be done, and I don't like the idea of changing exiftool to allow multiple format modifiers, so I'm not sure what to suggest here.

- Phil
Title: Re: Specify starting number/letter for %c
Post by: Hayo Baan on July 08, 2019, 04:02:35 PM
There’s always a regexp that could be applied to change the suffixes ;D
Title: Re: Specify starting number/letter for %c
Post by: taob on July 09, 2019, 11:11:34 AM
Phil,

I don't think overloading the semantics of a format modifier would be the right way to do it either. How about adding a range specification to %c? That could simultaneously address both the numbering type and the start/stop points? I'll borrow from bash, but obviously the actual syntax might be different:

%c{4} - 4, 5, 6, 7, 8, ...
%c{0004} - 0004, 0005, 0006, 0007, 0008, ...
%c{a} - a, b, c, d, e, ...
%c{L} - L, M, N, O, P ...
%c{0..15} - 0, 1, 2, ... 13, 14, 15
%c{P..C} - P, O, N, ... E, D, C
%c{100..999..5} - 100, 105, 110, ... 985, 990, 995
%c{cam1,cam2,cam3} - cam1, cam2, cam3, cam1, cam2, cam3, cam1, ...

(mostly based on https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html)

There would be some duplication of functionality with existing modifiers, but both systems could be maintained for compatibility. And it does seem like a lot of work just to satisfy my own personal use case, but I'm just spitballin' here.  ;D
Title: Re: Specify starting number/letter for %c
Post by: taob on July 09, 2019, 11:13:12 AM
There’s always a regexp that could be applied to change the suffixes ;D

You mean within exiftool itself, or running a separate rename script afterwards (which is what I've been doing)? My way is rather inelegant, though... basically just renaming 'b' to 'a', 'c' to 'b', 'd' to 'c', etc.
Title: Re: Specify starting number/letter for %c
Post by: taob on July 09, 2019, 12:06:28 PM
Your idea sounds very powerful, but is more work than I think is justified by the demand for a feature like this.

How about simply allowing the specification of the starting number or letter? Although in my experience, most of the work is just adding the framework to allow for a new feature...  :-\

I don't need to update exiftool that often, so maybe I'll just keep a local patch that increments starting with 'a'.
Title: Re: Specify starting number/letter for %c
Post by: Phil Harvey on July 09, 2019, 03:49:04 PM
Whoa.  Somehow my post wound up in the bit bucket.  Here it is back again:

It could be done with exiftool:

1. run your command to rename the files with suffixes '', '-b', '-c', ...

2. exiftool -fileorder filename "-filename<${filename;s/-([b-z])\./'-'.chr(ord($1)-1).'.'/e}" DIR

Your idea sounds very powerful, but is more work than I think is justified by the demand for a feature like this.

- Phil