#1 2010-05-20 22:45

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

Reorder parts of file name and serialize every bulk of 9 files

FROM:
Tile_r3-c3_w12_st01_sec09.tif
Tile_r2-c3_w12_st01_sec09.tif
Tile_r2-c1_w12_st02_sec01.tif
TO:
Tile_Z{001}_Y{003}_X{003}.tif
Tile_Z{001}_Y{003}_X{002}.tif
Tile_Z{001}_Y{001}_X{002}.tif

Rules:
Moving the "r"-digit to X{} and pad to three digits.
Moving the "c"-digit to Y{} and pad to three digits.
Serialize the Z{} with "001" for the first group of nine files, then with "002" for the second, then...


Rules:
1) Move the parts:
1) RegEx: Replace expression "Tile_r(\d)-c(\d)_w12_st\d\d_sec\d\d" with "Tile_Z{}_Y{00$2}_X{00$1}" (skip extension)

2) Serialize first 9 files with "001", next 9 with "002", then next 9 with "003",...
2) PascalScript: <see below>

3) Move the serialize digits to the right place:
3) RegEx: Replace expression "(\d\d\d) (Tile_Z\{)(.+)" with "$2$1$3" (skip extension)


EDIT: The script below is not needed anymore, because of:

ReNamer 5.50+ Beta 28 (~23.05.2010)
* Added option to reset serialization index every N files;

const
  PADTO = 3; //amount of digits: 2=01 / 3=001 / 4 = 0004
  RESET = 9; //change counter every n files: 4 = 01,01,01,01,02,02,02,02,03,03,03,03,04,04,04,04,05,05...

var
  Index, Value: Integer;
  Digit : String;

begin
  Index := Index + 1;    
  IF (Index < 2) then
     Value := 1;  
  
  IF (Index > RESET) then
  begin
      Index := 1;
      Value := Value + 1;
  end;

  Digit :=  IntToStr(Value);
  if PADTO > 1 then
    while Length(Digit) < PADTO do
      Digit := '0'+Digit;
      
  //FileName := 'Z{'+Digit+'}' + ' ' 
  //+ '(File #' + IntToStr(Index) + ') -  ' +  FileName;  

 FileName := Digit + ' ' + FileName;   
end.







------  an different case:

First i didn't got the request right
so i serialized Z{} from "001" to "009" and reset the counter back to "001" after every 9 files.

Rules:
1) Move the parts:
1) RegEx: Replace expression "Tile_r(\d)-c(\d)_w12_st\d\d_sec\d\d" with "Tile_Z{}_Y{00$2}_X{00$1}" (skip extension)

2) Serialize every 9 files with "001" till "009":
2) PascalScript: <see below>

3) Move the serialize digits to the right place:
3) RegEx: Replace expression "(\d\d\d) (Tile_Z\{)(.+)" with "$2$1$3" (skip extension)

const
  PADTO = 3; //amount of digits: 2=01 / 3=001 / 4 = 0004
  RESET = 9; //reset count every n amount: 4 = 1,2,3,4,1,2,3,4,1,2,3...

var
  Index: Integer;
  Value: String;
  
begin
  Index := Index + 1;    
  IF (Index > RESET) then
      Index := 1;
     
  Value := IntToStr(Index);
  if PADTO > 1 then
    while Length(Value) < PADTO do
      Value := '0'+Value;
      
  FileName := Value + ' '+FileName;  
 
end.

renamermoveanddropparts.png

.

Last edited by Stefan (2010-05-30 20:57)


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

#2 2010-06-22 21:47

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

Re: Reorder parts of file name and serialize every bulk of 9 files

Another challenge:

I have 4200 files,

First 300
FROM:
name1
till
name300
rename TO:
TEST0001name1
till
TEST0001name300

AND:
name301 till name600
TO:
TEST0002name1 till TEST0002name300

AND:
name601 till name900
TO:
TEST0003name1 till TEST0003name300
and so on...
till
name3900 till name4200

So  "TESTxxxx" increase for every 300 files from 0001 till 0014.
and "nameyyy" is numbered from 1 to 300 for each bulk of 300.


So i tried this script:

As every time: try this with some duplicates of your real files first!
And note that this script only works for files named like the provided examples!


var
 str, digits: WideString;

begin

     str := ReplaceRegEx(WideExtractBaseName(FileName), '(.+?)\d+', '$1', False, True); 
     digits := ReplaceRegEx(WideExtractBaseName(FileName), '.+?(\d+)', '$1', False, True); 
 
 If (StrToInt(digits) > 0) AND (StrToInt(digits) < 301) Then 
 FileName := 'TEST0001' + str + digits;
  
 If (StrToInt(digits) > 300) AND (StrToInt(digits) < 601) Then 
 FileName := 'TEST0002' + str + IntToStr(StrToInt(digits) -300);

 If (StrToInt(digits) > 600) AND (StrToInt(digits) < 901) Then 
 FileName := 'TEST0003' + str + IntToStr(StrToInt(digits) -600);

 If (StrToInt(digits) > 900) AND (StrToInt(digits) < 1201) Then 
 FileName := 'TEST0003' + str + IntToStr(StrToInt(digits) -900);
 
 // --- here  more of this: 'TEST0004' till 'TEST0007' ---

 If (StrToInt(digits) > 2700) AND (StrToInt(digits) < 3001) Then 
 FileName := 'TEST0008' + str + IntToStr(StrToInt(digits) -2700);
 
 // --- here  more of this: 'TEST0009' till 'TEST0013' --- 
 
 If (StrToInt(digits) > 3900) AND (StrToInt(digits) < 4201) Then 
 FileName := 'TEST0014' + str + IntToStr(StrToInt(digits) -3900);


end.

See the WIKI for more about using Rules:
=> http://www.den4b.com/wiki/ReNamer:Rules

---

To Test this script you can create quickly 4200 files with this batch:

@ECHO OFF
REM set /p "amount=How many files do you want to create?"
set amount=4200
for /l %%i in (1,1,%amount%) do (copy nul name%%i >NUL)

Last edited by Stefan (2010-06-24 19:20)


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

#3 2010-06-23 19:51

by_him
Member
Registered: 2010-06-23
Posts: 5

Re: Reorder parts of file name and serialize every bulk of 9 files

Hi there,

Thank you so much!

However, I found it doesn't work if original file names are: x1, x2, x3... for example a1, a2, a3...  I don't understand why not (I have reviewed your batch and I don't take it)

Salutes!
Sam

Offline

#4 2010-06-23 20:28

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

Re: Reorder parts of file name and serialize every bulk of 9 files

Hi Sam, welcome! Nice to see you here.

by_him wrote:

However, I found it doesn't work if original file names are: x1, x2, x3... for example a1, a2, a3...

The script above works only for your first file name examples

FROM:
name1
TO:
TEST0001name1

due how i use "ReplaceRegEx" and build the new FileName

You have only to adjust the Reg expressions for "str" and "digits" and build the new FileName to suit your needs.
If you provide us a few examples of your real file names someone may help you to find the right matching pattern.


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

#5 2010-06-23 21:47

by_him
Member
Registered: 2010-06-23
Posts: 5

Re: Reorder parts of file name and serialize every bulk of 9 files

Instead of "name1, name2, name3...", it would be "a1, a2, a3...." Everything else is just the same.

I just revised your batch, and (.+?) should take into account a single alphanumeric character in the file name. I just don't understand. I also tried (.*?), (.)... to no avail.

I am testing on 10 files named a5, a6, a7... a14, just for testing purposes.

smile



Wait, I see what PROBABLY I am doing wrong now:

I am testing with this:

var
str, digits: WideString;

begin

str := ReplaceRegEx(FileName, '(.+?)\d+', '$1', False, True);
digits := ReplaceRegEx(FileName, '.+?(\d+)', '$1', False, True);

If (StrToInt(digits) > 5) AND (StrToInt(digits) < 7) Then
FileName := 'TEST0001' + str + digits;

end.

The problem is probably with last one:  FileName := 'TEST0001' + str + digits;

Arrgg

Last edited by by_him (2010-06-23 21:51)

Offline

#6 2010-06-24 07:10

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

Re: Reorder parts of file name and serialize every bulk of 9 files

by_him wrote:

Instead of "name1, name2, name3...", it would be "a1, a2, a3...." Everything else is just the same.

Then the RegEx and the script should work.

...and (.+?) should take into account a single alphanumeric character in the file name.

Yes your are right.

An little RegEx excursion:
- an single dot is an RegEx metachar to match one single sign, char/digit/space/sign
- the plus + means: match one-or-more of the regex right left before, here the dot.
So that means: "match one-or-more of any sign"

The question mark ? means: match non-greedy, match only as less as you can get to solve the regex

The parentheses (...) are for storing what is found by the regex pattern and for re-using this by using "$1" in the replacement.


I am testing on 10 files named a5, a6, a7... a14, just for testing purposes.
Wait, I see what PROBABLY I am doing wrong now:

I am testing with this:
FileName := 'TEST0001' + str + digits;

The problem is probably with last one:  FileName := 'TEST0001' + str + digits;

With the ReNamer-own var "FileName" the New Name is constructed.
With 'TEST0001' this text is inserted literally in front of the NewName,
increased from 0001 to 0014 depending  what is stored in the digit var,
followed by them what is stored in the "str" var, followed by an calculated number from the digit var.


All as you asked for.


by_him wrote:

Instead of "name1, name2, name3...", it would be "a1, a2, a3...." Everything else is just the same.

So you still want

FROM:
a1.ext
a2.ext
a4200.ext
TO:
TEST+ <4 digits from 0001 to 0014, change every 300> + <string from the original name> + <numbering from the original name but only 1 to 300>

All depends on the original name, i do no re-numbering here, OK?

ReNamer_Bulk_of_300_c16.png


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

#7 2010-06-24 17:51

by_him
Member
Registered: 2010-06-23
Posts: 5

Re: Reorder parts of file name and serialize every bulk of 9 files

Stefan,

Thank you for explaining. I already knew that, but it is not working with short names!!!

It is really weird.

If I "analyze" files as you did, it seems to be working. However, in the real "preview" main window, whether I "preview" or "rename", it doesn't work.

4730803332_d4d4b4bfec_b.jpg

Last edited by by_him (2010-06-24 17:55)

Offline

#8 2010-06-24 19:25

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

Re: Reorder parts of file name and serialize every bulk of 9 files

Ahh, NOW you came up with extensions!
Neither in your request nor in your analyze window you mention something about file extensions.

With file extensions my regex didn't work anymore.
We have to adjust them... or simple use only the "base name" (without the ext) as string to match on.

Just use "WideExtractBaseName(FileName)" instead of "FileName" like:
     str := ReplaceRegEx(WideExtractBaseName(FileName), '(.+?)\d+', '$1', False, True);
     digits := ReplaceRegEx(WideExtractBaseName(FileName), '.+?(\d+)', '$1', False, True);

So next time, just provide real file name patterns in the first place, OK?  big_smile

Salute, adiós, Hasta luego.


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

#9 2010-06-24 20:09

by_him
Member
Registered: 2010-06-23
Posts: 5

Re: Reorder parts of file name and serialize every bulk of 9 files

Holy SHITTTTT, man!!!! You are correct!!!

I just thought the extension was ignored automatically, and it was not important at all!!!!!

Arrrgggg, I am so sorry.

Extensions are not included, and I need them included:

a1.pic, a2.pic, a3.pic...

I just used "Extension" rule for it, and it works like a charm.

Offline

Board footer

Powered by FluxBB