File Mover Blog

June 30, 2024

How to move files to different destinations based on the file extension

How to move files to different destinations based on the file extension

Q: Since we are dealing with Pharma equipment where we are pulling data off. We would like to be able to split the data into ‘readable’ (ie Txt, excel) and permanent (ie PDF, Image) and place the file types in different subdirectories on the target. At this time, my only solution would be to create two separate rules to accomplish this. Given that there are so many features hidden in your tool that I keep learning about, I was wondering if that was a feature that is in the Mover that I have not found.

A: Yes this is possible using our Script option.

  • We used a Windows Folder as Source:

limagito file mover windows folder as source

  • We added the following Filename Include Filters. These are the file extensions we want to split to different destinations.

limagito file mover filename filter

  • In this example we added 4 destinations. Each Destination has a unique ID:
    • ID1
    • ID2
    • ID3
    • ID4

We’ll use this Destination ID in our script.

limagito file mover destination setup

  • Next, please open our Pascal Script option:

limagito file mover pascal script option

  • Enable and add the following ‘On Destinations’ Pascal Script:
Var
  tmpFileExt: String;
Begin
  psExitCode:= -1;
  // ... add your code here
  tmpFileExt := ExtractFileExt(psFilename);
  // psLogWrite(1, '', 'Check File Extension ' + tmpFileExt + ' from ' + psFilename);
  // Check If Destination ID is ID1 AND do we have a .txt file?
  If (psDestinationID = 'ID1') Then 
    If SameText(tmpFileExt, '.txt') Then
      psExitCode := 1; 
  // Check If Destination ID is ID2 AND do we have .xls/.xlsx files?
  If (psDestinationID = 'ID2') Then
    If SameText(tmpFileExt, '.xls') OR SameText(tmpFileExt, '.xlsx') Then
      psExitCode := 1; 
  // Check If Destination ID is ID3 AND do we have a .pdf file?
  If (psDestinationID = 'ID3') Then 
    If SameText(tmpFileExt, '.pdf') Then
      psExitCode := 1;  
  // Check If Destination ID is ID4 AND do we have .png/.jpg/.bmp files?
  If (psDestinationID = 'ID4') Then
    If SameText(tmpFileExt, '.png') OR SameText(tmpFileExt, '.jpg') OR SameText(tmpFileExt, '.bmp') Then
      psExitCode := 1;       
End.

limagito file mover different destinations based on the file extension

  • RunTime Log Result:

limagito file mover runtime log

This is is just an example of what is possible. If you need any help with this ‘different destinations based on the file extension’, please let us know.

Best Regards,

Limagito Team

#managedfiletransfer #filetransfer #filemanagement

SEARCH