#1 2021-06-15 14:18

Stamimail
Member
Registered: 2016-05-08
Posts: 81

How to increase a #number in random location in filenames?

abc -  #000 - defghijklmnop.pdf
abcdefghijklmnop -#001.pdf
abcdefghijklm - #002 - nop.pdf
#003 - abcdefghijklmnop.pdf

It's like I want to search for the numbers part and increase by 1.

Offline

#2 2021-06-24 13:32

Stamimail
Member
Registered: 2016-05-08
Posts: 81

Re: How to increase a #number in random location in filenames?

Too complicated?
OK, the same question without the "zero padding":

abc -  #0 - defghijklmnop.pdf
abcdefghijklmnop -#1.pdf
abcdefghijklm - #2 - nop.pdf
#3 - abcdefghijklmnop.pdf

how to solve this?

Does anyone know if regular expressions support search and replace manipulation.

Offline

#3 2021-06-26 10:37

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: How to increase a #number in random location in filenames?

Stamimail wrote:

abc -  #000 - defghijklmnop.pdf
abcdefghijklmnop -#001.pdf
abcdefghijklm - #002 - nop.pdf
#003 - abcdefghijklmnop.pdf

It's like I want to search for the numbers part and increase by 1.


FROM:
abc -  #000 - defghijklmnop.pdf
abcdefghijklmnop -#001.pdf
abcdefghijklm - #002 - nop.pdf
#003 - abcdefghijklmnop.pdf

TO:
abc -  #001 - defghijklmnop.pdf
abcdefghijklmnop -#002.pdf
abcdefghijklm - #003 - nop.pdf
#004 - abcdefghijklmnop.pdf


TRY:
this PascalScript ( https://www.den4b.com/wiki/ReNamer:Rules:PascalScript )

(* Find a literal #-sign plus three digits and increase the number *)  
(* https://www.den4b.com/forum/viewtopic.php?pid=12067#p12067 *)
var
  //Parts: TStringsArray;
  Parts: TWideStringArray;
  Part: WideString;
  PartsLen: Integer;

begin
  Parts := SubMatchesRegEx(FileName, '(.*)(#\d\d\d)(.*)', FALSE);
  If (Length(Parts) = 3)Then
    begin
          Part := Parts[1];
          Part := WideTrimChars(Part,'#');
          PartsLen := Length(Part);

          // do the math here:
          Part := IntToStr(StrToInt(Part) + 1 );
         //


            //pad number to original length:
            while Length(Part) < PartsLen do
              Part:='0'+Part;
          //

          Part:= '#' + Part;
      //WideShowMessage(Parts[0] + Part + Parts[2]);
  End;
  FileName := Parts[0] + Part + Parts[2];
end.







Or for any length of number exchange
     Parts := SubMatchesRegEx(FileName, '(.*)(#\d\d\d)(.*)', FALSE);
by
     Parts := SubMatchesRegEx(FileName, '(.*)(#\d+)(.*)', FALSE);



FROM:
#003 - abcdefghijklmnop.pdf
#3 - abcdefghijklmnop.pdf
abc -  #0 - defghijklmnop.pdf
abc -  #000 - defghijklmnop.pdf
abcdefghijklm - #002 - nop.pdf
abcdefghijklm - #2 - nop.pdf
abcdefghijklmnop -#001.pdf
abcdefghijklmnop -#1.pdf

TO:
#004 - abcdefghijklmnop.pdf
#4 - abcdefghijklmnop.pdf
abc -  #001 - defghijklmnop.pdf
abc -  #1 - defghijklmnop.pdf
abcdefghijklm - #003 - nop.pdf
abcdefghijklm - #3 - nop.pdf
abcdefghijklmnop -#002.pdf
abcdefghijklmnop -#2.pdf



 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#4 2021-06-27 13:17

Stamimail
Member
Registered: 2016-05-08
Posts: 81

Re: How to increase a #number in random location in filenames?

It works. Thank you very much.

Offline

Board footer

Powered by FluxBB