How to when files arrive, copy files from an other source directory
Q: I need some help on a Limagito rule I need to write :
- Check files into a source directory.
- When these files arrive, copy files from an other source directory with same filename but different extension.
ie :
Check files named 123456.pregen from c:\Test\Search\
Then copy file c:\Test\In\123456.pdf to c:\dest\
A: Please have a look at the following screenshots:
- We are using a Windows folder as source. The goal is to copy files from here to a destination. Which files will depend on the script we are going to add.
- File Filter Setup:
- Add %VSA as include Filename Filter (%VSA = Variable String A)
- The %VSA will contain the filenames we want to copy. Our Pascal script will add the filenames to this Var.
- Enable ‘Allow parameters in File Name filter’ (File Filter Setup – Advanced Tab):
- Open our Pascal Script option
- Add and enable the following ‘On Rule Begin’ Pascal Script:
- Do not forget to adjust the CtSearchPath (ctSearchFilter and ctSearchSubFolders) Const
Var iList: Integer; tmpFilename: String; tmpList: TstringList; Const ctSearchPath = 'C:\Test\Search\'; // Must end with a \ ctSearchFilter = '*.pregen'; ctSearchSubFolders = False; // False or True Begin psExitCode:= 0; psVSA := ''; // ... add your code here tmpList := psListFiles(ctSearchPath, ctSearchFilter, ctSearchSubFolders); Try For iList := 0 to (tmpList.Count-1) Do Begin tmpFilename := tmpList.Strings[iList]; tmpFilename := ChangeFileExt(tmpFilename, '.pdf'); psVSA := psVSA + tmpFilename + ';'; End; Finally tmpList.Free; End; // Debug psLogWrite(1, '', 'Filename filter as psVSA: ' + psVSA); // Set psExitCode If psVSA <> '' Then psExitCode := 1; End.
- We used a Windows folder as Destination:
- Function is set to Copy in our example but also Move is possible
- If function is set to Copy and you only want to copy the same files once, then please enable our File Memory option:
- RunTime log result:
I forgot on line. If I want to delete my pregen file after copy/move, where can I add it on code ?
In this case some adjustments to the pascal script are needed:
- Add and enable the following: ‘On Rule Begin’ Pascal Script
- Do not forget to adjust the CtSearchPath (ctSearchFilter and ctSearchSubFolders) Const
- Add and enable the following: ‘On Rule End’ Pascal Script
- The pregen files will be deleted only if no errors occurred
If you need any help with this question, please let us know.
Best Regards,
Limagito Team
#managedfiletransfer #filetransfer #filemanagement