File Copy with Destination path and name lookup
Q: I have a source folder that has a ton of subfolders and files with a guid type filename. I have the translation from the source path\filename to the new desired path\filename. Is there a way to do this in Limagito? I can put the list in any file format (delimited file, json, xml) or from a sql lookup. Is it possible to only copy files that it finds?
A: Should be possible using a csv file with a | (pipe) between source and destination files. I’ve added some screenshots to get you started.
– We used a Windows folder as Source:
– Open our Pascal Script option:
- Enable and Add the following Pascal Script:
- Do not forget to adjust the ctCSVFile Const value
- We’ll use this file to determine the Destination Path and File. Content example file we used (csv.txt):
- Be sure to use a | (pipe) as separator
Var
tmpName, tmpValue: String;
iList: Integer;
tmpList: TStringList;
Const
ctCSVFile = 'C:\Test\Csv\csv.txt';
Begin
psExitCode:= 0;
psVSA := '';
psVSB := '';
// ... add your code here
tmpList := TStringList.Create;
Try
tmpList.NameValueSeparator := '|';
Try
tmpList.LoadFromFile(ctCSVFile);
// Iterate
For iList := 0 to (tmpList.Count-1) Do
Begin
tmpName := tmpList.Names[iList];
tmpValue := tmpList.ValueFromIndex[iList];
If SameText(psFilePath+psFileName, tmpName) Then
Begin
psVSA := ExtractFilePath(tmpValue); // FilePath
psCreatePath(psVSA);
psVSB := ExtractFileName(tmpValue); // FileName
// Set Result
psExitCode := 1;
// Break
Break;
End;
End;
Except
psLogWrite(1, '', 'Error loading CSV: ' + ctCSVFile);
End;
Finally
tmpList.Free;
End;
End.
– Destination Setup:
- We used a Windows folder as Destination:
- Please use %VSA as Directory
- The parameter %VSA will contain data from the previous Pascal Script
- File Renaming Setup:
- RegEx: (.*)
- Replacement: %VSB
- Parameter %VSB will contain data from the previous Pascal Script
– RunTime Log Result:
If you need any help with this ‘name lookup’ question, please let us know.
Best Regards,
Limagito Team
#managedfiletransfer #filetransfer #filemanagement