Q: I am trying to append a folder name to a file name but having a little trouble. The file is under 1 or 2 subfolder. After the file move I would like to append the very last folder name to the file name , and I don’t want to copy the source folder structure. Can you help me.
A: Yes this is possible using some Pascal Script. We’ll need two destinations.
- The first destination must be our ‘Pascal Script’. This script will strip the immediate subfolder from the complete subfolder part.
- The second destination will be a Windows folder (WIN). In this destination we’ll rename the file using the info from the first destination (pascal script).
Let’s start with the first destination (Pascal Script):
Var
iList: Integer;
tmpEntry: String;
tmpList: TStringList;
Begin
psExitCode:= 1;
// ... add your code here
psVSA := Trim(psStringReplace(psFilePath, psSourcePath, ''));
If psVSA <> '' Then
Begin
tmpList := TStringList.Create;
Try
tmpList.Delimiter := '\';
tmpList.DelimitedText := psVSA;
psVSA := '';
// Iterate
For iList := (tmpList.Count - 1) DownTo 0 Do
Begin
tmpEntry := Trim(tmpList.Strings[iList]);
If tmpEntry <> '' Then
Begin
psVSA := tmpEntry;
Break;
End;
End;
Finally
tmpList.Free;
End;
End;
// Adjust
If psVSA <> '' Then
psVSA := psVSA + '_';
// Debug
psLogWrite(1, '', 'Stripped SubFolder: ' + psVSA);
End.
Next we’ll setup our second destination (WIN):
Don’t forget to disable the ‘Create SubDir’ option if you don’t want to copy the source folder structure.
File renaming setup:
RegEx: (.*)
Replacement: %VSA\1
RunTime Log:
#FileTransfer
Best regards,
Limagito Team