Q: How can i change the leading numbers, e.g.:
FROM:
1 - file 1.txt
2 - file 36.txt
TO:
16 - file 1.txt
17 - file 36.txt
A: First idea is to do this in two steps:
1.) remove leading numbers
2.) add new numbers starting at '16'
How-to:
- Select all files in Siren
( take care to have the files in the wanted order,
AND to select them top-down one-by-one, or all the same time,
because the %n parameter takes the selection order into account)
- Type this into the Expression field:
%f(s/^\d+//);%n{1,16,1}%f
- execute menu "Action > Recompute" for an preview
Explanation:
This are two expression, separated by an semicolon
%f(s/^\d+//)
;
%n{1,16,1}%f
The first expression is an regex search and replace
which search for leading digits and replace them with nothing, meaning: remove them.
The second adds an counter "%n" in the order the files are selected.
(if you don't see the right sequence 16,17,18,... un-select and select again)
The parameter {1,16,1} is an modifier and stands for {padding width, start at, step width}
Then the rest of the original (new computed from the first expression) file name is added by the %f variable.
- - -
But with Siren you can do it more then one way:
Q: How can i change the leading numbers, e.g.:
FROM:
1 - file 1.txt
2 - file 36.txt
TO:
16 - file 1.txt
17 - file 36.txt
A: You could use the "%N" (upper case N !!!) variable:
%N : a number contained in the base file name
A digit can indicate its position (1 by default)
The parameters of some "number" variables can be defined in "Options" ("Numbers" sub-menu).
They can be specified too directly in the expression inside a "{}" modifier (braces)
that postfixes the variable name.
For the numbers contained in the base file name: %N, %N1, %Nn ...
the usage is: "{ p, v, n }"
p : size / pad (length of the number, padded with zeros if needed)
v : value to add (positive or negative)
n : position of the number to extract. If negative, the extraction is done from the end.
How-to:
- Select all files in Siren
- Type this into the Expression field:
%N
- execute menu "Action > Recompute" for an preview
You will get:
001
002
(the number is padded with two zero as defined in "Options" IF your Siren settings is still the default)
OK, that have to be improved, and we have to see how to get the rest of the file name.
First, we do the adjustment of this numbers:
- modify the expression to %N{2}
You will get:
01
02
(do you remember the modifier "{ p, v, n }" for the number variable?
or more clearly: "{ padding width, value for calculation, pos of number to extract from the name }")
Since we wanted to add '15' to the leading numbers to get '16'
- modify the expression to %N{2,15}
You will get:
16
17
Done!
What please?
Ohh, you want the remaining part of the name too? OK:
To get the rest of the file name you can
- modify the expression to %N{2,15}%f
You will get:
161 - file 1.txt
172 - file 36.txt
The "%f" variable will get you the whole file name incl. the extension.
But since we do not need the first sign here (the digits '1' and '2') we can
add an modifier to the '%f' variable too to get the file name from the second sign to the end:
(Check the help for String modifier : "( )" to see how this works)
- modify the expression to %N{2,15}%f(2)
You will get:
16 - file 1.txt
17 - file 36.txt
Pretty fine! Done?
Yes, mostly. But what if i had file names like:
1 - file 1.txt
2 - file 36.txt
21 - file 4.txt
32 - file 6.txt
And with an expression like %N{2,15}%f
you will get:
161 - file 1.txt
172 - file 36.txt
3621 - file 4.txt
4732 - file 6.txt
Here i had to remove one time 1, and the other time 2 signs from the beginning?
I had to use %f(2) and then %f(3) depending on the amount of leading digits????
How can i do this????
Well, here i would use an other modifier for the "%f" variable:
- modify the expression to %N{2,15}%f[2]
You will get:
16file 1.txt
17file 36.txt
36file 4.txt
47file 6.txt
(IF your Siren settings is still the default and "-" is still the default "Array elements separators" in the options.
Check the help for String modifier : "[ ]" to learn how this works)
In short: that %f[2] will split your file name at the "-" delimiter, as set in the options,
and the '2' will get use the second part of the split-ed name.
Now just add the missing "space dash space":
- modify the expression to %N{2,15} - %f[2]
to get the wanted:
16 - file 1.txt
17 - file 36.txt
36 - file 4.txt
47 - file 6.txt
Done!
? please ?
Ok, Ok, i understand: what if you want to do the math on the second number from the file name?
To modify the second number found in the name, you can change the expression
to %N{2,15,2}
or
to %N2{2,15}
to get:
16
51
19
21
And to get the rest of the file name you can maybe use an regular expression
since the length of the name is different from file to file:
Expression: %b(s/(.+ )\d+/\1/)%N2{1,15}.*
(From the base name, match all till trailing digits, then drop those digits in the replacement)
What? You don't speak RegEx? That looks crazy as hell?
Nema problema!
Just use the power of Siren to do this for you and use the "%NN" variable.
See help Variables > Base > %NN
%NN, the "opposite" of %N : a non numeric string contained in the base file name
A digit can indicate its position (1 by default)
With that knowledge we can use this crude looking expression
%N%NN%N2.*
to get:
001 - file 001.txt
002 - file 036.txt
021 - file 004.txt
032 - file 006.txt
%N will hold the first number in the name
%NN the first non-digit part of the name
%N2 the second number in the name
.* just adds the original extension.
and that combined with the above explained number-variable modifiers
%N{1}%NN%N2{2,15}.*
you get the wanted:
1 - file 16.txt
2 - file 51.txt
21 - file 19.txt
32 - file 21.txt
or even change the first %N{1} to %N{2}
to get:
01 - file 16.txt
02 - file 51.txt
21 - file 19.txt
32 - file 21.txt
---------------------------
To show the possibilities, here an more complex example.
Again, modify the second number from the file name:
FROM:
1 - file 1 test1.txt
2 - file 36 check2.txt
21 - file 4 look3.txt
32 - file 6 adjust4.txt
Expression:
%N{1}%NN%N2{2,15}%NN2%N3{1}.*
TO GET:
1 - file 16 test1.txt
2 - file 51 check2.txt
21 - file 19 look3.txt
32 - file 21 adjust4.txt
Explanation:
%N to get the first number "32"
%NN to get the first non-number part " - file "
%N2 to get the second number "6" which get calculated by {2,15} to "21"
%NN2 to get the second non-number " adjust"
%N3 to get the thirs number "4"
With other renamers you would have to build an regex like:
%b(s/(.+ )\d+(.+)/\1/)%N2{2,15}%b(s/(.+)\d+(.+)/\2/).*
Compared to that the syntax of Siren is more then simple and user friendly.
---------------------------
Done?
Yes?
Phuu!
OK, your welcome!
Depending on your file name the way to your solution may differ from this examples.
But in the help you will find all possible variables to solve your challenge.
Often you just have to think about from an different point of view ;-)
And in the end you can always ask an question at the forum (but please take an clever
description for the subject line and provide real examples of your file name, thanks.)
Find me: Renumbering Re-Numbering Exchange Numbers Serialize
Serializing Digits do the math reckoning calculation computation counting
.