Pascal Script

  • 26 May

    Move 1 file to 1 location and another file to a different location

    Q: Is it possible to move 1 file to 1 location and another file to a different location but only when a file with a specific extension is present? I’m processing a job where I create a data file with print information and a PDFfile,  in the Main location there will be .csv file

    Main Location

    .csv

    At some point a pdf file will appear in the main location i.e.

    .csv

    .pdf

    Can I create a rule where

    1. It only starts when a .pdf is present
    2. Moves the .pdf file to 1 location and the .csv file to a different location?

    A: Yes this is possible using a bit of Pascal Script. We added some screenshots from an example to get you started.

    • We added a local Windows folder as Source:

    Limagito File Mover Source Setup

    • Important is to add the following FileName Include Filters. We’ll scan for ‘*.csv’ and ‘*.pdf’ files.

    Limagito File Mover Filename Include Filter

    • Open the Pascal Script option:

    Limagito File Mover Pascal Script option

    • Enable and Add the following ‘On Rule Begin’ Pascal Script:
    Begin
      psExitCode:= 1;
      // ... add your code here
      psVSA := '';
    End.

    Limagito File Mover Pascal Script

    • Enable and Add the following ‘On Destination’ Pascal Script:
    Var
      tmpExt: String;
      tmpFile: String;
    Begin
      psExitCode := 0;
      // ... add your code here
      tmpExt := ExtractFileExt(psFileName);
      // Check for pdf if csv exists
      If tmpExt = '.csv' Then
      Begin
        tmpFile := psStringReplace(psFileName, tmpExt, '.pdf');
        If FileExists(psFilePath + tmpFile) or (Pos(psFilePath + tmpFile, psVSA) <> 0) Then
        Begin
          psLogWrite(1, '', 'File ' + tmpFile + ' Exists');
          psVSA := psVSA + ';' + psFilePath + psFileName;
          psExitCode := 1;
        End;
      End;
      // Check for csv if pdf exists
      If tmpExt = '.pdf' Then
      Begin
        tmpFile := psStringReplace(psFileName, tmpExt, '.csv');
        If FileExists(psFilePath + tmpFile) or (Pos(psFilePath + tmpFile, psVSA) <> 0)  Then
        Begin
          psLogWrite(1, '', 'File ' + tmpFile + ' Exists');
          psVSA := psVSA + ';' + psFilePath + psFileName;
          psExitCode := 1;
        End;
      End;
    End.

    Limagito File Mover Pascal Script

    • Enable and Add the following ‘On Destinations‘ Pascal Script:
    Begin
      psExitCode := -1;
      // .csv files to Destination ID1
      If (psDestinationID = 'ID1') And (ExtractFileExt(psFileName) = '.csv') Then
        psExitCode := 1;
      // .pdf files to Destination ID2    
      If (psDestinationID = 'ID2') And (ExtractFileExt(psFileName) = '.pdf') Then
        psExitCode := 1;
    End.
    

    Limagito File Mover another file to a different location

    • Add two Destinations. Important, the first Destination (ID1) should receive hte csv files and the second Destination (ID2) should receive the pdf files.

    Limagito File Mover Destination Setup

    • RunTime Log Result. The Csv file goes to the first Destination and only when a pdf file with the same name exists. The pdf file itself goes to the second Destination.

    Limagito File Mover RunTime Log

    #Filetransfer #Filemanagement

    If you need any info about this request, please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team Pascal Script WIN
  • 23 May

    Get content of text file and use this as body for email

    Q: If I use Filemover to move or copy a txt file, is it possible to get the contents of that file, and then maybe include it in a Rule Event e-mail? I would like it as the e-mail body please.

    A: Yes this is possible. We’ll use some Pascal Script to read the content of the text file into a variable (%VSA). This variable will be used in the email setup of the SMTP destination.

    In our example we’ll scan for text files in a local Windows folder.

    Limagito File Mover get content of text file

    The ‘Include File Name’ filter is set to *.txt because we only want to pick up text files.

    Limagito File Mover Filename Include Filter

    Important, set the Function > Destination Option to ‘Exit Cyclus on Error’. The reason is that we are going to use two destinations. The first destination which is a Pascal Script will read the content of the text file in to the %VSA variable. If this doesn’t succeed then we should not go to the second ‘SMTP’ destination. We only want to sent the email (SMTP) if the read content of the source text file is successful.

    Limagito File Mover Function Setup

    As previously described, we are going to use two destinations. Important, the first one must be the ‘Pascal Script’ destination.

    Limagito File Mover Destination Setup

    Var
      tmpFile: String;
      tmpList: TStringList;
    Begin
      psExitCode:= 0;
      // ... add your code here
      tmpFile := psFilePath + psFileName;
      tmpList := TStringList.Create;
      Try
        Try
          tmpList.LoadFromFile(tmpFile);
          psVSA := tmpList.Text;
          psExitCode := 1;    
        Except
          psLogWrite(1, '', 'Error loading ' + tmpFile); 
        End;  
      Finally
        tmpList.Free;
      End;  
    End.

    Limagito File Mover get content of text file

    The second destination is SMTP. Some screenshots of the setup we used. We added the %VSA varaible in the Body of the email.

    Limagito File Mover get content of text file

    Limagito File Mover SMTP as Destination

    Limagito File Mover SMTP as Destination

    RunTime log result:

    Limagito File Mover RunTime Log

    Received email with the content of the text file in the body of the email:

    Limagito File Mover text content as body of email

     

    #Filetransfer #Filemanagement

    If you need any info about this request, please let us know.

    Best regards,

    Limagito Team

  • 22 May

    Manage the rule status change with the help of Pascal Script

    Q: We would like to manage the rule status change : turn HOLD, turn Release, etc. I didn’t find any “ps” command related to this need. Could you help us to stop/hold/enable status rules? Just missing this PS command to change rule status 😉

    Hope it exists…. based on type “psRuleChangeStatus( RuleID : Integer, newStatus : String/Integer… )” or something like that…
    A: In our latest version v2022.5.22.0 we added two new functions that will help you.
    ===============================================
    – Use psRuleSetHoldStatus to set the status of moving rule to HOLD. The RuleId can be found in the statusbar information.Function psRuleSetHoldStatus(_RuleId: Integer): Boolean;

    i.e. psRuleSetHoldStatus(1);
    ===============================================
    – Use psRuleSetReleaseStatus to set the status of moving rule to RELEASE. The RuleId can be found in the statusbar information.

    Function psRuleSetReleaseStatus(_RuleId: Integer): Boolean;

    i.e. psRuleSetReleaseStatus(1);
    ===============================================

    FYI: In this version we also added some new Pascal Script var that can be used for example in the ‘On Destination’ and ‘On Destinations’ Pascal Script options.
    • psFileDir
    • psFileSubDir
    • psFileSubDirFirst
    • psFileSubDirLast
    • psFilePath
    • psFileSubPath
    • psFileSubPathFirst
    • psFileSubPathLast
    Example:
    • WIN as Source, Root Path is C:\Scan\
    • During scan the following file was found: C:\Scan\Sub1\Sub2\Intro.pdf
    Result when using the new Pascal Script var will be:
    • psFileDir > C:\Scan\Sub1\Sub2
    • psFileSubDir > Sub1\Sub2
    • psFileSubDirFirst > Sub1
    • psFileSubDirLast > Sub2
    • psFilePath  > C:\Scan\Sub1\Sub2\
    • psFileSubPath > Sub1\Sub2\
    • psFileSubPathFirst > Sub1\
    • psFileSubPathLast > Sub2\

    #Filetransfer #PascalScript

    If you need any info about this ‘Manage the rule status change’ request, please let us know.

    Best regards,

    Limagito Team

1 12 13 14 15 16 17 18 29
SEARCH