Pascal Script

  • 01 Aug

    How to scan a folder to look for a number of files, then start the transfer?

    Q: How to scan a folder to look for a number of files, then start the transfer? We are a licensed customer of Limagito. Is it possible to scan a folder to look for 6 files, then start the transfer?  If there are less than 6 files, none of the files are transferred.

    A: This is possible with a Windows folder/Share [WIN] as Source. We added some screenshots to get you started.

    • Add Windows folder/share as Source:

    limagito file mover source setup

    •  Open our Pascal Script option:

    limagito file mover pascal script option

    • Please enable and add the following ‘On Rule Begin’ Pascal Script (script attached in txt file). You can modify the amount (ctMinFiles) or search filter (*.*) if needed.
    Var
      tmpCounter: Integer;
    Const
      ctMinFiles = 6;
    Begin
      psExitCode := 0;
      // ... add your code here
      // If you want to scan subirectories
      // tmpCounter := psCountFiles(psSourcePath, '*.*', True);
      // In this example we will not scan the subdirectories of the source folder
      tmpCounter := psCountFiles(psSourcePath, '*.*', False);
      If tmpCounter >= ctMinFiles Then
      Begin
        psLogWrite(1, '', 'Files count successful: ' + IntToStr(tmpCounter));     
        psExitCode := 1;
      End  
      Else
        psLogWrite(1, '', 'Not enough files, count: ' + IntToStr(tmpCounter));     
    End.

    limagito file mover look for a number of files

    • Click F9 and check the log window in the Pascal Script setup. It should show ‘Compiled Successfully’.

    limagito file mover pascal script compile result

     

    If you need any info about this ‘look for a number of files’ question, please let us know.

    Best regards,

    Limagito Team

  • 29 Jun

    How to increment the date in a filename by plus one day

    Q: Is it possible to rename a file containing a date string when copying it to increment the date in the filename by plus one day?

    where yyyymmddxx_I.p1.pdf the yyyymmdd will increase by +1

    Examples

    • Input: 2022010501_I.p1.pdf
      • Output: 2022010601_I.p1.pdf
    • Input: 2023123101_I.p1.pdf
      • Output: 2024010101_I.p1.pdf

    A: Yes this is possible. Please have a look at the following screenshots.

    • We used a Windows folder as Source (can be any other type of Source too):

    limagito file mover windows folder as source

    • Open our Pascal Script option:

    limagito file mover pascal script option

    • Enable and Add the following ‘On Destination’ Pascal Script:
    Var
     tmpFilename, tmpDateStr: String;
     tmpDate: TDateTime;
    Const
      ctDateFormatOld = 'YYYYMMDD'; ctDateSepOld = #0;
      ctDateFormatNew = 'YYYYMMDD';
    Begin
    (*
    Example:
    Input: 2022010501_I.p1.pdf
    Output: 2022010601_I.p1.pdf
    *)
      psExitCode:= 0;
      // ... add your code here
      tmpFilename := psFilename;
      If length(tmpFilename) >= 8 Then
      Begin
        Try
          tmpDateStr := Copy(tmpFilename, 1, Length(ctDateFormatOld));
          tmpDate := psStrToDate(tmpDateStr, ctDateFormatOld, ctDateSepOld);
          tmpDate := psIncDay(tmpDate, 1);
          psVSA := FormatDateTime(ctDateFormatNew, tmpDate);
          psExitCode:= 1;
        Except
          psLogWrite(1, '', 'Strip Date from File exception on ' + psFilePath + psFilename);
        End;
      End
      Else
      Begin
        psLogWrite(1, '', 'Strip Date length of File error on ' + psFilePath + psFilename);
      End;
    End.

    limagito file mover pascal script setup

    • Open our Destination setup

    limagito file mover destination setup

    • We used a Windows folder as Destination:

    limagito file mover windows folder as destination

    • Enable ‘Rename Files during Copy/Move’ and click the ‘Rename Filter Setup’ button:

    limagito file mover file rename option

    • Add the following ‘File Rename’ setup:
      • RegEx:  .{8}(.*)
      • Replacement:  %VSA\1

    limagito file mover file rename setup

    • RunTime Log result:

     

    limagito file mover runtime log result

    #mft #Filetransfer #rename

    If you need any info about this “increment the date in a filename” request, please let us know.

    Best regards,

    Limagito Team

  • 25 Jun

    Can file mover alert me if files haven’t moved from a folder

    How to alert me if files haven’t moved

    Q: We haven’t spoken in a while which means file mover is working great. I have a question though, can file mover alert me if files haven’t moved from a folder it has delivered some files to? I’m having some different trouble with an application which has just started. One input folder is sometimes not moving the files into the next application, when you click on the folder in this application it looks empty, but when you look at the folder in the OS you can see its got loads of files in.
    I would love to have an alert to say that there are 5 or more files in this folder, is there a problem.

    A: This is possible using our scripting option. Please have a look at the following screenshots. If you need any help, please let us know.

    • Important, the “Function” must be set to COPY
    • We added a Windows folder as Source (but any other Source types should work also)

    limagito file mover windows folder as source

    • In our example we want to count files older than 5 minutes so we added the following “File Date Include” filter:

    limagito file mover file filter setup

    • As Destination we added our “Pascal Script” option. The script will use an internal Counter psVIA (pascal script Variable Integer A) to count the amount of files we found.

    limagito file mover destination setup

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

    limagito file mover pascal script as destination

    • Please open our “Rule Events” option:

    limagito file mover rule events option

    • Select and enable “On Rule Begin” event and enable “Enable Pascal Script”. Add the following script which will reset our internal counter psVIA when the Rule begins scanning.
    Begin
      psExitCode:= 1;
      // ... add your code here
      psVIA := 0;
    End.

    limagito file mover rule events option

    • Select and enable “On Rule End” event and enable “Enable Pascal Script”. Add the following script. We use a second internal variable psVIB to create a memory function regarding the sending of the email.
    Const
      ctMaxFilesAllowed = 5;
    Begin
      psExitCode:= 0;
      // ... add your code here
      If (psVIA > ctMaxFilesAllowed) Then
      Begin
        If psVIB = 0 Then
        Begin
          psVIB := 1; 
          psExitCode := 1;
          psLogWrite(1, '', 'Send Email, Max files reached');
        End;  
      End
      Else
        psVIB := 0;  
    End.
    

    limagito file mover rule events option

    • Be sure to enable the “Use Pascal Script as Event Precondition” under Options for the “On Rule End’ event. The result of the Pascal Script (psExitCode) will determine of an email will be sent or not.

    limagito file mover rule events option

    • Setup email for the “On Rule End” event.
      • Enable “Enable Mail” option
      • Setup Email
      • Setup Common (or Rule) SMTP. The Common setup can be used by other Rules and is mostly used.

    limagito file rule events option

    limagito file mover email setup

    • We are using the Google SMTP server in this example:

    limagito file mover common smtp setup

    • RunTime Log result:
      • The first time the Rule was triggered, it found more than 5 files and an email was sent.
      • The second time the amount of files was still more than 5 files but we didn’t sent an email. We will wait until the amount of files is lower again to reset this memory status.

    limagirto file move runtime log result

    #Filetransfer #SMTP

    If you need any info about this “alert me if files haven’t moved” option, please let us know.

    Best regards,

    Limagito Team

     
1 6 7 8 9 10 11 12 29
SEARCH