#11 2012-12-07 02:57

narayan
Senior Member
Registered: 2009-02-08
Posts: 471

Re: Move files to folder (from part of file name)

While the tokens look similar ($n), they are different: In the RegEx rule, such a token represents a matched RegEx subexpression, but in the Rearrange rule it represents substrings separated by the delimiter.

Offline

#12 2012-12-11 10:00

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

Re: Move files to folder (from part of file name)

Sorry for the delay.

I have done a PascalScript.

FROM:
History Ch Russia Land Of The Tsars E01 Of4.avi
History Ch Russia Land Of The Tsars E02 Of4.avi
History Ch The Crusades Crescent And The Cross E01 Of4 - Disc One The First Crusade Part 1.avi
History Ch The Crusades Crescent And The Cross E02 Of4 - Disc One The First Crusade Part 2.avi
History Ch The Crusades Crescent And The Cross E03 Of4 - Disc Two The Second And Third Crusades.avi
series name s08 e10 blah blah.avi

TO: (note the added \ back slash: new sub folders will be created)
History Ch Russia Land Of The Tsars\History Ch Russia Land Of The Tsars E01 Of4.avi
History Ch Russia Land Of The Tsars\History Ch Russia Land Of The Tsars E02 Of4.avi
History Ch The Crusades Crescent And The Cross\History Ch The Crusades Crescent And The Cross E01 Of4 - Disc One The First Crusade Part 1.avi
History Ch The Crusades Crescent And The Cross\History Ch The Crusades Crescent And The Cross E02 Of4 - Disc One The First Crusade Part 2.avi
History Ch The Crusades Crescent And The Cross\History Ch The Crusades Crescent And The Cross E03 Of4 - Disc Two The Second And Third Crusades.avi
series name\s08\series name s08 e10 blah blah.avi

{
Move Files To Corresponding Sub Folders

FROM:
series name e10 blah 1.avi
series name e10 blah 2.avi
series name e14 blah 1.avi
series name e14 blah 2.avi
series other name e10 blah 1.avi
series other name e10 blah 2.avi
series other name e17 blah 1.avi
series other name e17 blah 2.avi
other series name s08 e13 blah.avi
other series name s08 e14 blub.avi
TO:
(note the added \ back slash: new sub folders will be created here, based on part of the filename)
other series name\s08\other series name s08 e13 blah.avi
other series name\s08\other series name s08 e14 blub.avi
series name\series name e10 blah 1.avi
series name\series name e10 blah 2.avi
series name\series name e14 blah 1.avi
series name\series name e14 blah 2.avi
series other name\series other name e10 blah 1.avi
series other name\series other name e10 blah 2.avi
series other name\series other name e17 blah 1.avi
series other name\series other name e17 blah 2.avi

RULE:
- Take first part of filename till "E\d\d"
- Create new folder from this part
- Move file to that folder.
- But if found "S\d\d" in filename create a additional sub folder S\d\d

USE:
PascalScript
}

var
  Parts: TStringsArray;
  
begin
  Parts := SubMatchesRegEx(FileName, '(.+) (S\d\d)(.+)', FALSE);
  If (Length(Parts) > 0) then 
    begin
      FileName := Parts[0]+'\'+Parts[1]+'\'+Parts[0]+' '+Parts[1]+Parts[2]
      Exit
    end;
  
  Parts := SubMatchesRegEx(FileName, '(.+) (E\d\d.+)', FALSE);
  If (Length(Parts) > 0) then 
    begin
      FileName := Parts[0]+'\'+Parts[0]+' '+Parts[1]
    end;
end.

HTH? big_smile


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 2012-12-20 10:16

richman
Member
Registered: 2012-12-03
Posts: 6

Re: Move files to folder (from part of file name)

Thank you very much Stefan - that was great.

If anyone needs to sort and rename their files I have enclosed details of my complete rmp.file
This will format TV programs as S01 E10 and sort them into folders. It also replaces . with spaces and capitalize each word.



[Rule0]
ID=RegEx
Config=EXPRESSION:%28%5Cd%29of%28%5Cd%29+;REPLACE:E0%241+of%242+%2D+;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule1]
ID=RegEx
Config=EXPRESSION:%28%5Cd%5Cd%29of%28%5Cd%5Cd%29;REPLACE:E%241+of%242+%2D+;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule2]
ID=RegEx
Config=EXPRESSION:%28%5Cd%29of%28%5Cd%29;REPLACE:E0%241+of%242+%2D+;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule3]
ID=RegEx
Config=EXPRESSION:Season+%28%5Cd%29+;REPLACE:S0%241+;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule4]
ID=RegEx
Config=EXPRESSION:Series+%28%5Cd%29+;REPLACE:S0%241+;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule5]
ID=RegEx
Config=EXPRESSION:%28%5Cd%29x%28%5Cd%5Cd%29;REPLACE:S0%241+E%242;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule6]
ID=RegEx
Config=EXPRESSION:%28%5Cd%5Cd%29x%28%5Cd%5Cd%29;REPLACE:S0%241+E%242;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule7]
ID=RegEx
Config=EXPRESSION:s%28%5Cd%5Cd%29e%28%5Cd%5Cd%29;REPLACE:S%241+E%242;CASESENSITIVE:0;SKIPEXTENSION:1
Marked=1

[Rule8]
ID=Replace
Config=TEXTWHAT:%5B;TEXTWITH:%28;WHICH:3;SKIPEXTENSION:0;CASESENSITIVE:0;USEWILDCARDS:0
Marked=1

[Rule9]
ID=Replace
Config=TEXTWHAT:%5D;TEXTWITH:%29;WHICH:3;SKIPEXTENSION:0;CASESENSITIVE:0;USEWILDCARDS:0
Marked=1

[Rule10]
ID=CleanUp
Config=BRACKETSROUND:0;BRACKETSSQUARE:0;BRACKETSCURVY:0;SPACESDOT:1;SPACESCOMMA:0;SPACESUNDERSCORE:0;SPACESPLUS:0;SPACESHYPHEN:0;SPACESWEB:0;SPACESSKIPVERSIONS:0;SPACESFIX:1;SKIPEXTENSION:1;PREPAREFORSHAREPOINT:0;INSERTSPACEBEFORECAPITALS:0
Marked=1

[Rule11]
ID=Replace
Config=TEXTWHAT:%5F;TEXTWITH:+;WHICH:3;SKIPEXTENSION:0;CASESENSITIVE:0;USEWILDCARDS:0
Marked=1

[Rule12]
ID=Case
Config=WHAT:3;SKIPEXTENSION:1;EXTENSIONALWAYSLOWERCASE:1;FORCECASE:0;FRAGMENTSTEXT:
Marked=1

[Rule13]
ID=Remove
Config=TEXT:ac3%2A%7C%2Axvid%2A%7C%2Advdrip%2A%7C%2Amp3%2A%7C%2Ax264%2A%7C%2Awidescreen%2A%7C%2A+576p%2A%7C%2A720p%2A%7C%2Ahdtv%2A%7C%2Apdtv%2A%7C%2A+aac%2A%7C%2A468p%2A%7C%2A1080p;WHICH:3;SKIPEXTENSION:1;CASESENSITIVE:0;USEWILDCARDS:0
Marked=1

[Rule14]
ID=Replace
Config=TEXTWHAT:Season+One+;TEXTWITH:+S01+;WHICH:3;SKIPEXTENSION:0;CASESENSITIVE:0;USEWILDCARDS:0
Marked=1

[Rule15]
ID=Replace
Config=TEXTWHAT:Series+1%2A%7C%2ASeries+2;TEXTWITH:+S01+%2A%7C%2AS02;WHICH:3;SKIPEXTENSION:0;CASESENSITIVE:0;USEWILDCARDS:0
Marked=1

[Rule16]
ID=CleanUp
Config=BRACKETSROUND:0;BRACKETSSQUARE:0;BRACKETSCURVY:0;SPACESDOT:1;SPACESCOMMA:0;SPACESUNDERSCORE:0;SPACESPLUS:0;SPACESHYPHEN:0;SPACESWEB:0;SPACESSKIPVERSIONS:0;SPACESFIX:1;SKIPEXTENSION:1;PREPAREFORSHAREPOINT:0;INSERTSPACEBEFORECAPITALS:0
Marked=1

[Rule17]
ID=Remove
Config=TEXT:%2D%2E;WHICH:2;SKIPEXTENSION:0;CASESENSITIVE:0;USEWILDCARDS:0
Marked=1

[Rule18]
ID=PascalScript
Config=SOURCE:%7B%0D%0AMove+Files+To+Corresponding+Sub+Folders%0D%0A%0D%0AFROM%3A%0D%0Aseries+name+e10+blah+1%2Eavi%0D%0Aseries+name+e10+blah+2%2Eavi%0D%0Aseries+name+e14+blah+1%2Eavi%0D%0Aseries+name+e14+blah+2%2Eavi%0D%0Aseries+other+name+e10+blah+1%2Eavi%0D%0Aseries+other+name+e10+blah+2%2Eavi%0D%0Aseries+other+name+e17+blah+1%2Eavi%0D%0Aseries+other+name+e17+blah+2%2Eavi%0D%0Aother+series+name+s08+e13+blah%2Eavi%0D%0Aother+series+name+s08+e14+blub%2Eavi%0D%0ATO%3A%0D%0A%28note+the+added+%5C+back+slash%3A+new+sub+folders+will+be+created+here%2C+based+on+part+of+the+filename%29%0D%0Aother+series+name%5Cs08%5Cother+series+name+s08+e13+blah%2Eavi%0D%0Aother+series+name%5Cs08%5Cother+series+name+s08+e14+blub%2Eavi%0D%0Aseries+name%5Cseries+name+e10+blah+1%2Eavi%0D%0Aseries+name%5Cseries+name+e10+blah+2%2Eavi%0D%0Aseries+name%5Cseries+name+e14+blah+1%2Eavi%0D%0Aseries+name%5Cseries+name+e14+blah+2%2Eavi%0D%0Aseries+other+name%5Cseries+other+name+e10+blah+1%2Eavi%0D%0Aseries+other+name%5Cseries+other+name+e10+blah+2%2Eavi%0D%0Aseries+other+name%5Cseries+other+name+e17+blah+1%2Eavi%0D%0Aseries+other+name%5Cseries+other+name+e17+blah+2%2Eavi%0D%0A%0D%0ARULE%3A%0D%0A%2D+Take+first+part+of+filename+till+%22E%5Cd%5Cd%22%0D%0A%2D+Create+new+folder+from+this+part%0D%0A%2D+Move+file+to+that+folder%2E%0D%0A%2D+But+if+found+%22S%5Cd%5Cd%22+in+filename+create+a+additional+sub+folder+S%5Cd%5Cd%0D%0A%0D%0AUSE%3A%0D%0APascalScript%0D%0A%7D%0D%0A%0D%0Avar%0D%0A++Parts%3A+TStringsArray%3B%0D%0A++%0D%0Abegin%0D%0A++Parts+%3A%3D+SubMatchesRegEx%28FileName%2C+%27%28%2E%2B%29+%28S%5Cd%5Cd%29%28%2E%2B%29%27%2C+FALSE%29%3B%0D%0A++If+%28Length%28Parts%29+%3E+0%29+then+%0D%0A++++begin%0D%0A++++++FileName+%3A%3D+Parts%5B0%5D%2B%27%5C%27%2BParts%5B1%5D%2B%27%5C%27%2BParts%5B0%5D%2B%27+%27%2BParts%5B1%5D%2BParts%5B2%5D%0D%0A++++++Exit%0D%0A++++end%3B%0D%0A++%0D%0A++Parts+%3A%3D+SubMatchesRegEx%28FileName%2C+%27%28%2E%2B%29+%28E%5Cd%5Cd%2E%2B%29%27%2C+FALSE%29%3B%0D%0A++If+%28Length%28Parts%29+%3E+0%29+then+%0D%0A++++begin%0D%0A++++++FileName+%3A%3D+Parts%5B0%5D%2B%27%5C%27%2BParts%5B0%5D%2B%27+%27%2BParts%5B1%5D%0D%0A++++end%3B%0D%0Aend%2E
Marked=1

[Filters]
AddFilesFromFolders=1
AddFoldersAsFiles=0
IncludeSubfolders=1
IncludeHidden=0
IncludeSystem=0
SkipRootFoldersAsFiles=0
MasksOnFileName=1
Masks=2012

Offline

Board footer

Powered by FluxBB