Second Pascal Script is based on the following user request:
We need some help on setting up a rule. The rule we are trying to setup is as follow. Source folder has files in it, example file names ABC-test.txt, 123_test.txt, and test_XYZ.txt. We have a destination folder called “Test”, and we have 3 folders under it called ABC, 123, and XYZ. We want the rule to separate the files and place them in their specified folders. For example, file ABC-test.txt will be placed into folder ABC, 123_test.txt file will be placed into folder 123, and text_XYZ.txt file will be place into folder XYZ. We want the files to be moved into the separated folders that matches their name.
> Add your Destination:
> Destination Setup, change the ‘Create Subdir, opt.’ to %VSB
> Add the following ‘On Rule Begin’ Pascal Script. Very important: the ctOutputPath contant must be the same as your destination path (first screenshot) !
VariList: Integer;tmpSub: String;tmpList: TStringList;ConstctOutputPath = ‘C:\Test\Out\’;BeginpsExitCode:= 1;// … add your code herepsVSA := ”;tmpList := TStringList.Create;TrypsListPaths(ctOutputPath, ‘*.*’, 0, tmpList);for iList := 0 to (tmpList.Count-1) doBegintmpSub := tmpList.Strings[iList];tmpSub := psStringReplace(tmpSub, ctOutputPath, ”);tmpList.Strings[iList] := tmpSub;End;psVSA := tmpList.CommaText;// DebugpsLogWrite(1, ”, ‘SubFolder found: ‘ + psVSA);FinallytmpList.Free;End;End.
VariList: Integer;tmpSub: String;tmpList: TStringList;ConstctOutputSubPathNone = ‘None\’;BeginpsExitCode:= 1;// … add your code herepsVSB := ctOutputSubPathNone;// IteratetmpList := TStringList.Create;TrytmpList.CommaText := psVSA;tmpList.Sort;for iList := (tmpList.Count-1) downto 0 DoBegintmpSub := tmpList.Strings[iList];tmpSub := psStringReplace(tmpSub, ‘\’, ”);psLogWrite(1, ”, ‘Sub: ‘ + tmpSub);if Pos(LowerCase(tmpSub), LowerCase(psFileName)) <> 0 ThenBeginpsVSB := tmpSub;Break;End;End;// DebugpsLogWrite(1, ‘Destination SubFolder will be: ‘, psVSB);FinallytmpList.Free;End;End.