Pascal Script

  • 29 Oct

    How to filter file from read content in file header data

    Q: How to filter file from read content in file Header data date=today yyyymmdd

    A: We received an example of the file we need the content from. The filename of this text file stays the same, it is being updated each day by the customer.

    This is an example of the content of this file where we need to read ‘RUNDATE=’ value and use it as ‘Include File Filter’.

    limagito file mover filter file from read content
    In our test setup we used a Windows folder as Source and Destination. Source and Destination can be any type. The text file where we need to read the content from and use it as filter must be located on a Windows folder or Share.
    limagito file mover test environment
    Subfolders Test Environment:
    – Data: contains the text file we will check for the ‘RUNDATE’ entry that will be used as file filter.
    – In: Files to be moved
    – Out: Destination of files
    Please open our ‘Pascal Script’ option:
    limagito file mover pascal script option

    Enable and add the following ‘On Rule Begin’ Pascal Script. I’ve attached the script (script.txt). Don’t forget to adjust the ctTxtFile Const to your actual setup. The script will load the text file when the Rule is triggered, it will strip the part after ‘RUNDATE=’ and will set this to our %VSA variable that will be used in the FileName Include Filter setup.

    Var
      iList: Integer;
      tmpEntry, tmpFile: String;
      tmpList: TStringList;
    Const
      ctRunDate = 'RUNDATE=';
      ctTxtFile = 'C:\Test\Customer\Data\fxrate0000_getdata.txt';
    Begin
      psVSA := '';
      psExitCode:= 0;
      tmpFile := ctTxtFile;
      psLogWrite(1, '', 'Searching for filter from File: ' + tmpFile);
      tmpList := TStringList.Create;
      Try
        Try
          tmpList.LoadFromFile(tmpFile);
          // Iterate
          For iList := 0 to (tmpList.Count - 1) Do
          Begin
            tmpEntry := AnsiUpperCase(tmpList.Strings[iList]);
            If pos(ctRunDate, tmpEntry) <> 0 Then
            Begin
              tmpEntry := psStringReplace(tmpEntry, ctRunDate, '');
              If tmpEntry <> '' Then
              Begin
                psVSA := '*' + tmpEntry + '*';
                psExitCode := 1; // Filter found
                // Debug
                psLogWrite(1, '', 'File Filter adjusted to: ' + psVSA);
                // Break
                Break;
              End;
            End;
          End;
         Except
           psLogWrite(1, '', 'LoadFromFileError, ' + tmpFile);
         End;
      Finally
        tmpList.Free;
      End;
    End.

    limagito file mover pascal script option
    Add the following File Filter Setup:
    limagito file mover file filter setup
    Important, do not forget to enable ‘Allow parameters in File Name Filter’:
    limagito file mover file filter advanced options
    Now enable and trigger the Rule. RunTime Log Result:
    limagito file mover runtime log result

    #filehandling #filetransfer #filemanagement

    If you need any help with this ‘filter file from read contents’ request, please let us know.

    Best Regards,

    Limagito Team

  • 30 Aug

    How to count the number of files transferred to destination

    Q: I have another question we have big differences as far as the number of images some of our agencies sending us and the destination vendor receiving. They are asking if Limagito can count the number of files transferred to destination.

    A: In this blog article we added some scripts to count the files sent to a Destination. Transferred files counter data will be written to a monthly csv file. Each scan will be an entry in the csv file (which can be handled in Excel). This is just an example and can be adjusted to your needs.

    • Open our Pascal Script option:

    limagito file mover pascal script option

    • Enable and add the following ‘On Rule Begin’ script:
      • psVIA: an Integer variable which will count the amount of files transferred during the scan
      • psVSA: a String variable which will be used as the filename of the counter csv ( i.e. 2023.august.csv )
      • psVSB: a String variable which will be used for the Date entry in the csv file ( first column )
    Begin
      psExitCode:= 1;
      // ... add your code here
      psVIA := 0;
      // Current Month counter csv filename -psVSA
      psVSA := FormatDateTime('YYYY.MMMM', Now) + '.csv';
      // Current Day - psVSB
      psVSB := FormatDateTime('YYYYMMDDHHNNSS', Now);
    End.

    limagito file mover on rule begin pascal script

    • Enable and add the following ‘On Rule End’ script. Don’t forget to adjust the ctCsvPath constant. This is where we will store the csv files.
    Var
      tmpData, tmpFile: String;
      tmpSuccess: Boolean;
      tmpList: TStringList;
    Const
      ctCsvPath = 'C:\Test\Csv\'; // Must end with a \
    Begin
      psExitCode:= 1;
      // Check if files were moved or copied
      If psVIA = 0 Then
        Exit;
      // Init Var
      tmpData := psVSB + ',' + IntToStr(psVIA);
      tmpFile := ctCsvPath + psVSA;
      tmpSuccess := True;
      tmpList := TStringList.Create;
      Try
        If FileExists(tmpFile) Then
        Begin
          Try
            tmpList.LoadFromFile(tmpFile);
          Except
            tmpSuccess := False;
            psLogWrite(1, '', 'LoadFromFile, ' + tmpFile + ' error, counter data will not be saved: ' + tmpData);
          End;
        End
        Else
          tmpList.Add('Date,Value');
        // Check
        If tmpSuccess Then
        Begin
          tmpList.Add(tmpData);
          // Save To File
          Try
            tmpList.SaveToFile(tmpFile);
            psLogWrite(1, '', 'SaveToFile ' + tmpFile + ' successful');
          Except
            psLogWrite(1, '', 'SaveToFile ' + tmpFile + ' error, could not save counter data: ' + tmpData);
          End;
        End;
      Finally
        tmpList.Free;
      End;
    End.

    limagito file mover on rule end pascal script

    • Set Function Destination Option to ‘Exit Cyclus on Error’. This will skip a next Destination if an error occurs. The last Destination will be a Script where we increase the amount of files transferred so we want to make sure that the previous Destination(s) were successful.

    limagito file mover function setup

    • The last Destination should be the following Pascal Script:

    limagito file mover destination setup

    Begin
      psExitCode:= 1;
      // ... add your code here
      psVIA := psVIA + 1;
    End.

    limagito file mover pascal script as destination

    • Counter values will be stored in a monthly csv file which can be handled in Excel (or alternative):

    limagito file mover count files transferred to destination

    limagito file mover count files transferred to destination

     

    If you need any info about this ‘count the number of files transferred’ request, please let us know.

    #mft #filetransfer #filemanagement

    Best regards,

    Limagito Team

  • 11 Aug

    How to send zpl file to Zebra printer using Limagito file mover

    Q: How to send zpl file to Zebra printer. Do you have a solution in Limagito to send Zpl files to a printer? Zpl is a standard language for label printers.
    A: On request we added an option in Limagito File Mover v2023.8.10.0. The customer did some successful tests. These new options should be able to send other Zpl like type of files (EPL,..) to printers too.

    • In our example we used a Windows folder as Source, searching for zpl files:

    limagito file mover windows folder as source

    • We enabled ‘Exclude Files In Use’ because we don’t want to touch source .zpl file that are still being created:

    limagito file mover exclude files in use

    • Please set the Filename Include filter to *.zpl because we only need this type of files:

    limagito file mover filename include filter

    • Our Rule will be triggered every 30 seconds using a scan timer (Schedule Setup button):

    limagito file mover scan timer setup

    • As function we used ‘Move’ because after a successful print we want to delete the source .zpl file:

    limagito file mover function setup

    • As Destination we are going to use a Script:

    limagito file mover as Destination

    Var
      iList: Integer;
      tmpInfo, tmpFile, tmpString: String;
      tmpList: TStringList;
    Begin
      psExitCode:= 0;
      // ... add your code here
      tmpFile := psFilePath + psFileName;
      // Do Send
      tmpList := TStringList.Create;
      Try
        tmpList.CommaText := psGetPrinters;
        If tmpList.Count > 1 Then
        Begin
          For iList := 0 To (tmpList.count-1) Do 
            psLogWrite(1, '', 'Installed printer [' + IntToStr(iList+1) + ']: ' + tmpList.Strings[iList]);
          psLogWrite(1, '', 'Default printer: ' + psGetDefaultPrinter);
        End
        Else
          psLogWrite(1, '', 'No printer installed');        
        psLogWrite(1, '', 'Send file "' + tmpFile + '" to printer');
        Try
          tmpList.Clear;
          tmpList.LoadFromFile(tmpFile);
          If tmpList.Count > 0 Then
          Begin
            tmpString := tmpList.Text;
            // Method 1
            tmpInfo := psPrintRawString(tmpString, '');
            // Method 2
            // tmpInfo := psPrintRawList(tmpList, '');
            // Debug
            If tmpInfo <> '' Then
            Begin
              psLogWrite(1, '', 'Sent to printer error: ' + tmpInfo);
            End Else
            Begin
              psExitCode := 1;  
              psLogWrite(1, '', 'Sent to printer successfully: ' + tmpFile);
            End;
          End
          Else
          psLogWrite(1, '', 'Found empty file: ' + tmpFile);
        Except
          psLogWrite(1, '', 'LoadFromFileError: ' + tmpFile);
        End;
      Finally
        tmpList.Free;
      End;
    End.
    

    The script above will load the content of the .zpl (or other raw type of files) and will send this data to a selected printer.

            // Method 1
            tmpInfo := psPrintRawString(tmpString, ”);

    By default we’ll use the ‘Default’ printer in Windows which means the Zebra printer should be set as Default printer. If you want to use a Zebra printer that is not set to default in Windows you’ll need to add the printer name to the function.

    Suppose the installed Zebra printer name is: My Zebra Printer

            // Method 1
            tmpInfo := psPrintRawString(tmpString, ‘My Zebra Printer’);

    To help you with the printer names, the script will wrote the names in the RunTime log if you trigger the Rule (please check the output of the RunTime log in the screenshot below).

    limagito file mover send zpl file to Zebra printer

    • RunTime Log result:

    limagito runtime log

    If you need any info about this new ‘zpl file to Zebra printer’ option, please let us know.

    #zpl #zebra #filetransfer #filemanagement

    Best regards,

    Limagito Team

    By Limagito-Team Pascal Script Printer , , ,
1 3 4 5 6 7 8 9 27
SEARCH