Q: I’m trying to move a file that’s within 1 directory and rename the file so that it includes the directory name
Source: C:\Source1\File.txt
Destination: C:\Destination\Source1_File.txt
I want it to take the directory name that it is contained in, then string it to the front of the filename, but move it to it’s destination C:\Destination\.
We would only want it to pertain to the previous directory by 1 level.
- C:\Source1\File1.txt => C:\Destination\Source1_File1.txt
- C:\Source1\Sub\File2.txt => C:\Destination\Sub_File2.txt
A: Yes this is possible using some ‘Pascal Script’
Let’s start with the Source, we added a Windows folder:

In the ‘Directory Filter’ setup we enabled include scanning of subdirectories (optional, is not a must):

Destinations setup, important the first destination must be a ‘Pascal Script’:

First Destination should be a ‘Pascal Script’. We used ‘Source1’ as default PreFix for the Source Root Folder (you can adjust this):
Var
tmpPos: Integer;
tmpSubDir: String;
Const
ctRootPrefix = 'Source1';
Begin
psExitCode:= 1;
// ... add your code here
psVSA := '';
tmpSubDir := '%SFS';
tmpPos := pos('\', tmpSubDir);
If tmpPos<>0 Then
Begin
psVSA := Copy(tmpSubDir, tmpPos + 1, Length(tmpSubDir) - tmpPos);
psLogWrite(1, '', 'Stripped Prefix from SubDir: ' + tmpSubDir + ' : ' + psVSA);
End
Else
psVSA := ctRootPrefix;
End.

Second Destination is a windows folder where the source files should be moved/copied to:


Enable and setup File Renaming in the Windows Destination:

File Renaming setup:
- RegEx: (.*)
- Replacement: %VSA_\1

RunTime Log result:

Output Folder result:


If you need any
help , please let us know.
Regards,
Limagito Team