Topic: In-filename renumbering with a hitch ...

A more or less peculiar problem of sorts with a hobby of mine, historic data: various folders with filenames following a given naming scheme consisting of LOCATION and (PRODUCT), both of which are the same in the folder I am working on. As in 'speaking filenames': you always know from which folder the file comes should I have to create a collage.

Groupings therein are represented by a leading two-digit number. This is followed by a hyphen and a three-digit dec/binary size indicator. Finally there is a hyphen and a two digit file number.

My 'problem' is that it may happen that a certain Grouping has to be included between existing files, meaning that I have to rename all files from file [X] onward, keeping the original numbers but increased by one. So files with '19'  go '20', files with '20' go '21', files with '21' go '22', etc. ... as far as I understand one would require a temporary files table or 'top-to-bottom' rename mechanism to avoid double filenames. Can Siren do this? Everything I tried did not work (but then I may be plain stupid). Thanks in advance!

Example names:

LName (PName) 17-400-26.txt
LName (PName) 18-200-11.txt
LName (PName) 19-200-01.txt
LName (PName) 19-200-02.txt
LName (PName) 19-200-03.txt
LName (PName) 19-400-01.txt
LName (PName) 19-400-02.txt
LName (PName) 19-400-03.txt
LName (PName) 19-400-04.txt
LName (PName) 19-400-05.txt
LName (PName) 19-400-06.txt
LName (PName) 19-400-07.txt
LName (PName) 19-400-08.txt
LName (PName) 19-400-09.txt
LName (PName) 20-200-01.txt
LName (PName) 20-200-02.txt
LName (PName) 20-400-01.txt
LName (PName) 20-400-02.txt
LName (PName) 20-400-03.txt
LName (PName) 21-400-01.txt
LName (PName) 22-400-01.txt
LName (PName) 23-400-01.txt
LName (PName) 24-200-01.txt

Re: In-filename renumbering with a hitch ...

Hello and welcome,

Here is what I've understood : you want to create "space" after a "group" (for example "19") by renaming the following files :
for example, from :
LName (PName) 19-400-07.txt
LName (PName) 19-400-09.txt
LName (PName) 20-200-01.txt
LName (PName) 20-400-01.txt
LName (PName) 20-400-02.txt
LName (PName) 21-400-01.txt
LName (PName) 22-400-01.txt
to :
LName (PName) 19-400-07.txt
LName (PName) 19-400-09.txt
LName (PName) 21-200-01.txt
LName (PName) 21-400-01.txt
LName (PName) 21-400-02.txt
LName (PName) 22-400-01.txt
LName (PName) 23-400-01.txt

Siren can achieve this using the following kind of renaming expression on the "20", "21" etc. groups :

%NN%N{2,1,1}%f(-11)

Here is a step by step explanation using two file names :
LName (PName) 20-400-02.txt
LName (PName) 21-400-01.txt

%NN : will extract the first non numeric character string
    "LName (PName) "
    "LName (PName) "
%N{2,1,1} : will extract the first numeric character string, add 1 to it and format the result on two characters
    "21" giving "LName (PName) 21"
    "22" giving "LName (PName) 22"
%f(-11) : will extract the last 11 characters of the file name
    "-400-02.txt" giving "LName (PName) 21-400-02.txt"
    "-400-01.txt" giving "LName (PName) 22-400-01.txt"

You can find more details in Siren's help.

Hoping this will answer your needs.

Re: In-filename renumbering with a hitch ...

Please note,

renaming '20' to '21' will give you an error message, because '21' is already present.




That's why I have added an temporary sign or string to the new name,
which is not already part of the file name, like here for example a '#'

%NN%N{2,1,1}%b(-7)#.%e





Explanation:
%NN >>> non numeric character string
%N{2,1,1} >>> first numeric character string and do the math
%b(-7) >>> seven last signs from BASE name
# >>> additional sign to prevent complicated file names
.%e >>> the orign extension



Do a second run to remove that sign again:
%f(s/#//)

Re: In-filename renumbering with a hitch ...

You are right Stefan, I didn't think to this.

As Siren renames the files following the selection order, another solution could be to select them from the "highest" to the "lowest".
That way : 24 is renamed 25 then 23 is renamed 24 etc.

Thanks for your help.

Re: In-filename renumbering with a hitch ...

@Rémi, @Stefan:
Thanks for your answers and hints. It took me a second to understand the parameters; having it explained this way is far better than trying to understand helpfiles. However I have some comments. As Stefan wrote, the chances of creating pseudo-duplicate filenames is high. I say "pseudo" as they are not true duplicates but simply incorrectly handled files.

Here the possibility of completely switching the parsing of Siren from ascending to descending (renaming highest-numbered files first instead of starting from the lowest) would avoid having to use dirty workarounds, as the one suggested by Stefan. As indicated by Rémi Siren proceeds per selection order ... nobody likes to manually select fifty or more files just to operate top-down instead of bottom-up processing so a hardcoded switch in sorting order (asc/desc) would be required here. I am sure that there are more operations that would also profit from this, be it only by reducing steps in larger jobs.

I had a closer look at the help file and I can not seem to find a generic "until filename end" variable. Sure, using %f(-11) inserts the last eleven characters of the filename, but that creates havoc if filenames include additional comments, as in

LName (PName) 21-200-01 (1945, Museum).txt
LName (PName) 21-200-02 (Citation Website).txt
LName (PName) 22-200-01 (1964-JAN-12).txt

The only way aound that (as far as I can see) is to manually count the leading letters including the counter element, then add that into the brackets. Per example "LName (PName) " that would be %f(17). Not particulary nice nor user friendly, but appears to work. Have I missed this function or is there really no other way?

Thanks for all your help!

Re: In-filename renumbering with a hitch ...

You can do this using a regular expression. This can replace the "%f(-11)" and handle any string following the numeric pattern  :

%f(s/^.* \d\d(-\d\d\d-\d\d.*)$/\1/)

7 (edited by Stefan 2019-01-28 20:54:35)

Re: In-filename renumbering with a hitch ...

Additional explanation, if I may:

So Rémis' complete expression for your case would be:

%NN%N{2,1,1}%f(s/^.* \d\d(-\d\d\d-\d\d.*)$/\1/)

instead of:
%NN%N{2,1,1}%f(-11)

where the last one is a fix count,
and the first one is a flexible regular expression:
match everything from start till 'space', two digits,
then match and store a hyphen, three digits.... and so on.



And just in case you have more than two first digits
(as you didn't provide real names as examples...) use something like that:
%NN%N{2,1,1}%f(s/^.* \d+(-\d\d\d-\d\d.*)$/\1/)

Re: In-filename renumbering with a hitch ...

@Rémi, @Stefan:

Thank you both, again. I have tried the whole matter with the parameters

%NN%N{2,1,1}#%f(s/^.* \d\d(-\d\d\d-\d\d.*)$/\1/)

which so far worked fine. Note the "#%f"; this inserts the hash char as next character behind the first number block to prevent duplicate collisions (as Stefan pointed out). Real name example after renaming thus:

...
Selb (Lorenz Hutschenreuther) 11#-400-01 (1925-1939).tif
Selb (Lorenz Hutschenreuther) 11#-400-02 (1925-1939).tif
...

This of course has to be removed in a second run or a generic search&replace (e.g. TotalCommander MultiRenameTool). As pointed out before, this last step could be completely dropped if Siren had a toggle-able asc/desc processing preset.

Re: In-filename renumbering with a hitch ...

Hello,

There is maybe a solution to solve this two phase renaming (my siren skills are a bit rusty (sounds weird roll).
An alternative way to select the files in reverse order could be to select them when they are listed in reverse order.
To achieve this, the file list has to be "reversed" : just click on the "Current name" column header.

You may wonder : the order needed is the "numeric pattern" one, not the file names. Their prefixes can be different.
The solution is a bit tricky : as for any column, the files can be sorted on the "New name" one.
So, by entering an expression extracting the "numeric pattern" it could be used as sort key.
This sorting expression could be : %f(s/^.*?(\d+-\d+-\d+).*$/\1/)

Rémi

Re: In-filename renumbering with a hitch ...

@Rémi:

Can confirm: switched sort via click on CURRENT NAME, then hit [CTRL]-[A] to select all. Used parameters:

%NN%N{2,1,1}%f(s/^.* \d\d(-\d\d\d-\d\d.*)$/\1/)

Siren works as required. Problem solved and I'm a happy camper. Saves me TONS of hassle now.

Thanks a lot to both of you!