File Mover Blog

June 12, 2023

How to copy a raw file if a pdf file with the similar name exists

Q: How to copy a raw file if a pdf file with the similar name exists. I am trying to have a rule run that when the PDF exists in the folder then to copy our .raw file of a similar name. But if the PDF doesn’t exist that means the run isn’t done yet. So we need it to scan the folder looking for a new pdf if there is one the .raw file will then copy. Right now we run a PowerShell to do the work but maybe there’s a better way.

A: So this would  mean:
– Limagito Rule would scan for .raw files
– If .raw files is found > scan different folder (and subfolders) for .pdf file with similar name
– If pdf file exists then copy .raw file

Should be possible, we prepared some screenshots.

– Source Setup, we used a local Windows folder as Source:

limagito file mover windows folder as source

– File Filter Setup:

limagito file mover file filter setup
– Open our Pascal Script option:

limagito file mover pascal script option

– Enable and add the following ‘On Destinations‘ Pascal Script. Do not forget to adjust the pdf Search Path const, must end with a \

Var
  tmpFilename: String;
  tmpList: TStringList;
Const
  ctSearchPath = 'C:\Test\Nova\Pdf\';    
Begin
  psExitCode:= 0;
  tmpList := Nil;
  tmpFilename := ChangeFileExt(psFileName, '.pdf');
  // ... add your code here
  Try
    tmpList := psListFiles(ctSearchPath, tmpFilename, True);  
    If Assigned(tmpList) And (tmpList.Count > 0) Then
    Begin
      psExitCode := 1;
      psLogWrite(1, '', 'Found ' + tmpFilename + ' in ' + ctSearchPath);
    End
    Else
      psLogWrite(1, '', tmpFilename + ' not available yet in ' + ctSearchPath);
  Finally
    tmpList.Free;
  End;  
End.

limagito file mover on destinations pascal script

– Enable File Memory (we only want to copy the same .raw file once)

limagito file mover file memory option

– We used Copy as Function (that is why we enabled our File Memory option)

limagito file mover function setup

– Add Destination for .raw files

limagito file mover destination setup

– RunTime Log result

+ at our first try the corresponding pdf was not available yet
+ at our second try we found the corresponding pdf file and copied the raw file

limagito file mover runtime log result

#filetransfer #mft #filemanagement
If you need any info  about this ‘similar name exists’ request, please let us know.

Best regards,

Limagito Team

By Limagito-Team How-to Share:
SEARCH