#11 2013-04-13 22:20

Dirk
Member
Registered: 2013-04-05
Posts: 91

Re: Avoid renaming already renamed files? Serialize only new file

OK, thanks Stefan,

It would be the same examples:

Crash_Canyon_12.08.25_17-55_viva_25_TVOF_XX.mpg.avi
Crash_Canyon_12.08.26_19-35_viva_25_TVOF_XX.mpg.avi
Crash_Canyon_13.03.05_20-45_viva_30_TVOF_XX.mpg.avi
Der_rosarote_Panther_12.08.25_09-15_sw3_5_TVOF_XX.mpg.avi
Die_Simpsons_12.06.15_18-10_pro7_30_TVOF_XX.mpg.avi
Die_Simpsons_12.06.15_18-40_pro7_25_TVOF_XX.mpg.avi
Die_Simpsons_12.06.16_18-10_pro7_30_TVOF_XX.mpg.avi
Die_Simpsons_12.06.16_18-40_pro7_25_TVOF_XX.mpg.avi
Roseanne_12.07.17_17-10_orf1_20_TVOF_XX.mpg.avi
Roseanne_12.07.17_17-10_orf1_20_TVOF_XX.mpg.avi
Futurama_13.03.26_02-00_pro7_20_TVOF_XX.mpg.avi
Futurama_13.03.29_02-00_pro7_20_TVOF_XX.mpg.avi
Futurama_13.04.26_02-00_pro7_20_TVOF_XX.mpg.avi
Futurama_11.03.26_02-00_pro7_20_TVOF_XX.mpg.avi


To:

Crash Canyon 1.mpg.avi
Crash Canyon 2.mpg.avi
Crash Canyon 3.mpg.avi
Der rosarote Panther 1.mpg.avi
Die Simpsons 1.mpg.avi
Die Simpsons 2.mpg.avi
Die Simpsons 3.mpg.avi
Die Simpsons 4.mpg.avi
Roseanne 1.avi
Roseanne 2.avi
Futurama 1.avi
Futurama 2.avi
Futurama 3.avi
Futurama 4.avi

And if you would add these files again or new files (or suppose they differ slightly in the file name having the same pattern) to the same folder the above files are in after the files above are already renamed like they are, the enumerations continue where the last one has stopped of each series:

Crash_Canyon_12.08.25_17-55_viva_25_TVOF_XX.mpg.avi
Crash_Canyon_12.08.26_19-35_viva_25_TVOF_XX.mpg.avi
Crash_Canyon_11.08.26_19-35_viva_25_TVOF_XX.mpg.avi
Der_rosarote_Panther_12.08.25_09-15_sw3_5_TVOF_XX.mpg.avi
Die_Simpsons_12.06.15_18-10_pro7_30_TVOF_XX.mpg.avi
Die_Simpsons_12.06.16_18-40_pro7_25_TVOF_XX.mpg.avi
Die_Simpsons_12.07.15_18-10_pro7_30_TVOF_XX.mpg.avi
Die_Simpsons_12.06.26_18-40_pro7_25_TVOF_XX.mpg.avi
Roseanne_12.07.17_17-10_orf1_20_TVOF_XX.mpg.avi
Roseanne_12.07.17_17-10_orf1_20_TVOF_XX.mpg.avi
Futurama_13.03.26_02-00_pro7_20_TVOF_XX.mpg.avi
Futurama_13.03.26_02-00_pro7_20_TVOF_XX.mpg.avi
Futurama_13.03.29_02-00_pro7_20_TVOF_XX.mpg.avi
Futurama_13.04.26_02-00_pro7_20_TVOF_XX.mpg.avi

To:

Crash Canyon 4.mpg.avi
Crash Canyon 5.mpg.avi
Crash Canyon 6.mpg.avi
Der rosarote Panther 2.mpg.avi
Die Simpsons 5.mpg.avi
Die Simpsons 6.mpg.avi
Die Simpsons 7.mpg.avi
Die Simpsons 8.mpg.avi
Roseanne 3.avi
Roseanne 4.avi
Futurama 5.avi
Futurama 6.avi
Futurama 7.avi
Futurama 8.avi

And adding the next files, the same again.

Offline

#12 2013-04-15 15:56

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

Re: Avoid renaming already renamed files? Serialize only new file

The challenge in English words is:

Having some existent, already numbered files e.g.
Crash Canyon 01.mpg.avi
Crash Canyon 02.mpg.avi
Crash Canyon 03.mpg.avi

and adding new files like
Crash_Canyon_11.08.26_19-35_viva_25_TVOF_XX.mpg.avi
Crash_Canyon_12.08.25_17-55_viva_25_TVOF_XX.mpg.avi
Crash_Canyon_12.08.26_19-35_viva_25_TVOF_XX.mpg.avi

and want to
1. drop everything behind "first Space -here still seen as 'underscore'- followed by a Digit"
2. add numbering based on already existent files




Thats more complicated since the script have to work with different file name at the same time now.


I have played around a bit because of remembering
seeing code to program a Array function from Denis.

So I have done this test which works for me (if I have not overseen something).
I can guess it's not as elegant as could be but it work for this few files provided.


FROM:
Crash_Canyon_11.08.26_19-35_viva_25_TVOF_XX.mpg.avi
Crash_Canyon_12.08.25_17-55_viva_25_TVOF_XX.mpg.avi
Crash_Canyon_12.08.26_19-35_viva_25_TVOF_XX.mpg.avi

Crash Canyon 01.mpg.avi
Crash Canyon 02.mpg.avi
Crash Canyon 03.mpg.avi
Der_rosarote_Panther_12.08.25_09-15_sw3_5_TVOF_XX.mpg.avi
Der rosarote Panther 1.mpg.avi
Die_Simpsons_12.06.15_18-10_pro7_30_TVOF_XX.mpg.avi
Die_Simpsons_12.06.16_18-40_pro7_25_TVOF_XX.mpg.avi
Die_Simpsons_12.06.26_18-40_pro7_25_TVOF_XX.mpg.avi
Die_Simpsons_12.07.15_18-10_pro7_30_TVOF_XX.mpg.avi

Die Simpsons 1.mpg.avi
Die Simpsons 2.mpg.avi
Die Simpsons 3.mpg.avi
Die Simpsons 4.mpg.avi
Futurama 1.avi
Futurama 2.avi
Futurama 3.avi
Futurama 4.avi
Futurama_13.03.26_02-00_pro7_20_TVOF_XX.mpg.avi
Futurama_13.03.29_02-00_pro7_20_TVOF_XX.mpg.avi
Futurama_13.04.26_02-00_pro7_20_TVOF_XX.mpg.avi

Roseanne 001.avi
Roseanne 002.avi
Roseanne_12.07.17_17-10_orf1_20_TVOF_XX.mpg.avi

TO:
Crash Canyon 01.avi
Crash Canyon 02.avi
Crash Canyon 03.avi
Crash Canyon 04.avi
Crash Canyon 05.avi
Crash Canyon 06.avi

Der rosarote Panther 1.avi
Der rosarote Panther 2.avi
Die Simpsons 1.avi
Die Simpsons 2.avi
Die Simpsons 3.avi
Die Simpsons 4.avi
Die Simpsons 5.avi
Die Simpsons 6.avi
Die Simpsons 7.avi
Die Simpsons 8.avi

Futurama 1.avi
Futurama 2.avi
Futurama 3.avi
Futurama 4.avi
Futurama 5.avi
Futurama 6.avi
Futurama 7.avi

Roseanne 001.avi
Roseanne 002.avi
Roseanne 003.avi




DO:

* Backup your files first.

* Add this three rules
    1) Replace: Replace all "_" with " " (skip extension)
    2) Remove: Remove all ".mpg" (skip extension)
    3) PascalScript: (see below)

* Add your files to ReNamer

* Clean up the file names (with the first two rules) by clicking at PREVIEW

* Click at the NewName column to get the file names in the right order for the script, e.g.:
    Crash Canyon 01.mpg.avi
    Crash Canyon 02.mpg.avi
    Crash Canyon 03.mpg.avi
    Crash Canyon 11.08.26 19-35 viva 25 TVOF XX.avi
    Crash Canyon 12.08.25 17-55 viva 25 TVOF XX.avi
    Crash Canyon 12.08.26 19-35 viva 25 TVOF XX.avi
Important for the script: the already existent files must be at top, numbered top to bottom: 1,2,3...
Because this is the whole trick: storing existent names in a array and then get the last existent for the renaming of the newly added files.


* Do an another PREVIEW now while in correct order. The file names should become modified now as wanted.

* If the preview went fine, do the actual renaming



EDIT:
I had thought on this before but forgotten already:
This script will not work for files with numbering already higher than a date.

For example
    Crash Canyon 11.08.26 19-35 viva 25 TVOF XX.avi
    Crash Canyon 23.mpg.avi
because the order after the preview would still be
    Crash Canyon 11.08.26 19-35 viva 25 TVOF XX.avi
    Crash Canyon 23.mpg.avi
and my script would fail.

Have to think about an other way to get the files in wanted order...

EDIT 2:
Interims solution, replace date with '999' cool

1) Replace: Replace all "_" with " " (skip extension)
2) Remove: Remove all ".mpg" (skip extension)
3) RegEx: Replace expression "(\d\d\.\d\d\.\d\d)" with "999" (skip extension)
4) PascalScript:

Result:
    Crash Canyon 23.mpg.avi
    Crash Canyon 999 19-35 viva 25 TVOF XX.avi

Done!



The PascalScript

var
  FileArray: TStringsArray;

procedure FileArray_Add(const S: WideString);
begin
  SetLength(FileArray, Length(FileArray)+1);
  FileArray[Length(FileArray)-1] := S;
end;

function FileArray_Exists(const S: WideString): Boolean;
var I: Integer;
begin
  Result := False;
  for I:=0 to Length(FileArray)-1 do
    if WideSameText(FileArray[i], S) then
      begin Result := True; Break; end;
end;

function FileArray_Get(const S: WideString): WideString;
var 
 ret:WideString;
 I: Integer;
begin
  for I:=0 to Length(FileArray)-1 do
    if WideSameText(FileArray[i], S) then
      begin 
         ret := FileArray[i] + '?' + FileArray[I+1] 
         Result := ret; 
      end;
end;

var
  BaseName,FileExte,sLastNumber,sSerial,tmp,LastName:WideString;
  Parts: TstringsArray;
  iMath,iPadLen:Integer;

begin
  BaseName := WideExtractBaseName(FileName);
  FileExte := WideExtractFileExt(FileName);
                     //RegEx for existent "file name 03.ext"
  Parts    := SubMatchesRegEx(BaseName, '^(.*\w)\s(\d+)$', False);
  if Length(Parts) = 2  then 
  begin
     FileArray_Add(Parts[0]);
     FileArray_Add(Parts[1]);
  end
  else
  begin
             //RegEx for newly added "file name 1.2.2013 more text more 20 text.ext"
    Parts    := SubMatchesRegEx(BaseName, '^(.*?\w)\s(\d.+)$', False);
    if Length(Parts) = 2  then 
    begin
       tmp := Parts[0];
       if(  FileArray_Exists(tmp) )Then
       begin
          tmp         := FileArray_Get(tmp);
          Parts       := WideSplitString( tmp, '?');
          sLastNumber := Parts[1];
          iPadLen     := length(sLastNumber);
          
          if(Parts[0] <> LastName) Then sSerial := '';
          if(sSerial = '') Then 
             iMath    := StrToInt(sLastNumber) +1
          else
             iMath    := StrToInt(sSerial) +1;           
           
         sSerial     := IntToStr(iMath);
         While (Length(sSerial) < iPadLen) Do sSerial := '0'+sSerial;
             
         FileName    := Parts[0] + ' ' + sSerial + FileExte;
         LastName    := Parts[0];
      end;
    end;
  end;
end.

See our wiki for an how-to using PascalScript rule >> http://www.den4b.com/wiki/ReNamer:Rules:PascalScript

NOTE: this script works for your provided file name examples only due to the used RegEx pattern.
RegEx for existent "file name 03.ext" 
Parts    := SubMatchesRegEx(BaseName, '^(.*\w)\s(\d+)$', False);

RegEx for newly added "file name 1.2.2013 more text more 20 text.ext"
Parts    := SubMatchesRegEx(BaseName, '^(.*?\w)\s(\d.+)$', False);




If this script had helped someone, please help Denis too and donate some money for to pay the cost for hosting this side, thanks.

.

Last edited by Stefan (2013-04-15 16:13)


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

#13 2013-04-15 19:48

Dirk
Member
Registered: 2013-04-05
Posts: 91

Re: Avoid renaming already renamed files? Serialize only new file

Thank you very much, Stefan.

Roseanne 003

DO:

* Backup your files first.

* Add this three rules
    1) Replace: Replace all "_" with " " (skip extension)
    2) Remove: Remove all ".mpg" (skip extension)
    3) PascalScript: (see below)

* Add your files to ReNamer

* Clean up the file names (with the first two rules) by clicking at PREVIEW

* Click at the NewName column to get the file names in the right order for the script, e.g.:
    Crash Canyon 01.mpg.avi
    Crash Canyon 02.mpg.avi
    Crash Canyon 03.mpg.avi
    Crash Canyon 11.08.26 19-35 viva 25 TVOF XX.avi
    Crash Canyon 12.08.25 17-55 viva 25 TVOF XX.avi
    Crash Canyon 12.08.26 19-35 viva 25 TVOF XX.avi
Important for the script: the already existent files must be at top, numbered top to bottom: 1,2,3...

It looks so:
http://i.imm.io/12ZIc.png
http://i.imm.io/12ZJa.png
http://i.imm.io/12ZJk.png
http://i.imm.io/12ZJo.png
http://i.imm.io/12ZJu.png

EDIT 2:
Interims solution, replace date with '999' cool

1) Replace: Replace all "_" with " " (skip extension)
2) Remove: Remove all ".mpg" (skip extension)
3) RegEx: Replace expression "(\d\d\.\d\d\.\d\d)" with "999" (skip extension)

It looks:
http://i.imm.io/12ZL8.png

EDIT 2:
Interims solution, replace date with '999' cool

1) Replace: Replace all "_" with " " (skip extension)
2) Remove: Remove all ".mpg" (skip extension)
3) RegEx: Replace expression "(\d\d\.\d\d\.\d\d)" with "999" (skip extension)
4) PascalScript:

Result:
    Crash Canyon 23.mpg.avi
    Crash Canyon 999 19-35 viva 25 TVOF XX.avi

Done!

Now it is (message: 7 identical file names): http://i.imm.io/12ZOF.png

I guess, I do anything wrong, but do not know what at the moment.

Offline

#14 2013-04-15 20:39

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

Re: Avoid renaming already renamed files? Serialize only new file

Dirk wrote:

Now it is (message: 7 identical file names): http://i.imm.io/12ZOF.png


Important

Stefan wrote:

* Click at the NewName column to get the file names in the right order for the script, e.g.:

Important for the script: the already existent files must be at top, numbered top to bottom: 1,2,3...
Because this is the whole trick: storing existent names in a array and then get the last existent for the renaming of the newly added files.

Check your settings and  use natural order sorting




.


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

#15 2013-04-15 21:06

Dirk
Member
Registered: 2013-04-05
Posts: 91

Re: Avoid renaming already renamed files? Serialize only new file

Thank you, Stefan.

Check your settings and  use natural order sorting

OK, sorry.

Renaming in two steps stays kept (trying to rename in one step fails)? So, first rule 1 and rule 2, then sort by new name, then rule 3 and 4? http://i.imm.io/130bj.png

Done rule 1 and 2 and sorting by new name seem to work: http://i.imm.io/130cq.png

But rule 3 and 4 do not work: http://i.imm.io/130d9.png

Do not know what I am missing.

I tried step 1 again and it failed, then a second try and it worked.

I did:

0. add all of the files (old ones and new ones) to ReNamer
1. preview rules 1 and 2 (if checked uncheck rules 3 and 4)
2. sort by new file name
3. rename
4. uncheck rules 1 and 2
5. check rules 3 and 4
6. rename

Offline

Board footer

Powered by FluxBB