Pascal Script

  • 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

     
  • 31 May

    How to convert from XML to JSON format

    Q: We receive some files in XML format. Could you please confirm, if Limagito tool can convert XML files to JSON format? If yes, Do we have any limitations while converting the file type? Please let us know if you need any additional information.

    A: We added an option in version v2023.5.31.0 to achieve this.

    • Our Source will be a Windows folder

    limagito file mover Windows folder as source

    • We added the following include Filename filter because we only want to scan for *.xml files:

    limagito file mover filename filter

    • We’ll need a Pascal Script to convert the xml file to a Json file so we added Pascal Script as Destination:

    limagito file mover destination setup

    • We noticed that the xml we received from the customer was not a valid xml so we added some extra code (line 18) in the script to adjust this

    limagito filemover xml to json

    • Pascal Script we used (don’t forget to adjust the ctOutputPath const):
    Var
     tmpFileInput, tmpFileOutput, tmpResult: String;
     tmpXmlText: String;
     tmpList: TStringList;
    Const
      ctOutputPath = 'C:\Test\Out_JSon\'; // Must end with a \ 
    Begin
      // Init Var
      tmpFileInput := psFilePath + psFileName;
      tmpFileOutput := ctOutputPath + ChangeFileExt(psFileName, '.Json');
      psExitCode:= 0;
      // Read non valid Xml file and adjust before creating Json File
      tmpList := TStringList.Create;
      Try
        Try
          tmpList.LoadFromFile(tmpFileInput);
          tmpXmlText := tmpList.Text;
          tmpXmlText := psStringReplace(tmpXmlText, '-<', '<'); // Adjust Non Valid Xml
          // psLogWrite(1, '', 'StringReplace Xml Result: ' + tmpXmlText); // Debug
          tmpResult := psXmlTextToJSonFile(tmpXmlText, tmpFileOutput, True, True, True, True);
          If tmpResult = '' Then
          Begin
            psLogWrite(1, '', 'Saved Json Data to ' + tmpFileOutput);      
            psExitCode := 1;
          End  
          Else
            psLogWrite(1, '', tmpResult);
        Except
          psLogWrite(1, '', 'Load Xml from ' + tmpFileInput + ' Exception');
        End;
      Finally
        tmpList.Free;
      End;
    End.

    limagito file mover convert from xml to json

    In the example above we used The following function:

    Function psXmlTextToJSONFile(Const aXmlText, aJsonFile: String; Const aXmlParse, aXmlPack, aJsonIndent, aJsonEscape: Boolean): String;

    The psXML functions have a aXmlPack option that determines the format returned, Pack = False returns all tags as values with multiple nested levels of objects, Pack = True is simpler and easier to process but does lose some tag names.

    aXmlPack = False : all XML content is converted into Json values, each level with two or three names: #attributes is an optional object from opening tag, #Name
    is the string from <Tag>, and #children which is an array of other Json objects and arrays nested within the tag.

    aXmlPack = True : tags are converted to Names and their content to Values, or nested objects. For a single record, a single object is returned with the tag names
    lost, for multiple records (ie tags of the same name) an array is created with each record being an object.

     

    • RunTime Log Result:

    limagito file mover xml to json runtime log result

    • Json File Result:

     

    limagito filemover xml to json

    • Another available Pascal Script function that can be used only when source xml is valid (direct file to file conversion):

    Function psXmlFileToJSONFile(Const aXmlFile, aJsonFile: String; Const aXmlPack, aJsonIndent, aJsonEscape: Boolean): String;

    • Pascal Script will result in:
    Var
     tmpFileInput, tmpFileOutput, tmpResult: String;
    Const
      ctOutputPath = 'C:\Test\Out_JSon\'; // Must end with a \ 
    Begin
      // Init Var
      tmpFileInput := psFilePath + psFileName;
      tmpFileOutput := ctOutputPath + ChangeFileExt(psFileName, '.Json');
      psExitCode:= 0;
      // Xml File To JSon File
      tmpResult := psXmlFileToJSonFile(tmpFileInput, tmpFileOutput, True, True, True);
      If tmpResult = '' Then
      Begin
        psLogWrite(1, '', 'Saved Json Data to ' + tmpFileOutput);  
        psExitCode := 1;
      End  
      Else
        psLogWrite(1, '', tmpResult);
    End.
    

    limagito file mover convert from xml to json

    #filetransfer #mft #filemanagement #xml #json

    If you need any info  about this ‘Convert from XML to JSON format’ request, please let us know.

    Best regards,

    Limagito Team

  • 28 May

    Create an empty file named done.txt as all the files have been moved

    Q: We are using your software for some simple file moving automation. We find it very reliable and we would like to convert our existing CMD and ps scripts to Limagito rules. We have a script which performs the following steps:

    • Copy a directory and its contents from an FTP source only if the directory name matches a certain pattern (LQJ_yyyymmdd) > OK
    • Transfer the contents of the directory to an FTP destination in the folder /Replica/yyyymmdd/LQJ > OK
    • Create an empty file named done.txt as soon as all the files have been moved to the destination (step 2) in the FTP folder /Replica/yyymmdd

    Could you give me a hint about how to perform the last step?

    A: This is possible using some Pascal Script we created for you.

    Please open the Pascal Script setup:

    limagito file mover pascal script

    • Enable and Add the following ‘On Rule Begin’ Pascal Script. The result of psVSB will be used as parameter (%VSB) in the directory filter setup.
    Begin
      psExitCode:= 1;
      // ... add your code here
      psVSA := FormatDateTime('YYYYMMDD', Now);
      psVSB := '*_' + psVSA + ';' + '*\*_' + psVSA + '\*';
      //
      psLogWrite(1, '', psVSB);
    End.

    limagito file mover on rule begin pascal script

    • Enable and add the following ‘On Rule End’ Pascal Script. This script will create the Done.txt file ‘On Rule End’ when all files were transferred successfully. Don’t forget to adjust the ctDonePath ( must end with a \ ).
    Var
      tmpList: TStringList;
      tmpFile: String;
    Const
      ctDonePath = 'C:\Test\Pressor\Replica\';
    Begin
      psExitCode:= 0;
      tmpFile := ctDonePath + psVSA + '\Done.txt';
      // ... add your code here
      If (psCurrentFilesSrcError = 0) And (psCurrentFilesDstError = 0) Then
      Begin
        tmpList := TStringList.Create;
        Try
          tmpList.Text := 'Dummy Content';
          Try
            psCreatePath(ctDonePath + psVSA);
            tmpList.SaveToFile(tmpFile);
            // Debug
            psLogWrite(1, '', 'Save To File ' + tmpFile + ' Successful');
            // set ExitCode Successful
            psExitCode := 1;
          Except
            psLogWrite(1, '', 'Save To File ' + tmpFile + ' Error');
          End;
        Finally
          tmpList.Free;
        End;
      End
      Else
        psLogWrite(1, '', tmpFile + ' will not be created due to source or desitnation error(s)');
    End.

    limagito file mover on rule end pascal script

    • Directory setup, be sure to enable ‘Include Subdirectories’ and ‘Exclude Basedirectory’:

    limagito file mover directory setup

    • Set Dir Name include filter to:  %VSB

    The value of parameter %VSB will be set in the ‘On Rule Begin’ Pascal Script.

    limagit file mover directory name filter

    • Set Dir Name exclude filter to exclude certain unwanted subfolders:

    limagito file mover directory exclude filter

    • Be sure to allow the use of parameters in the Directory Name filter:

    limagito file mover directory filter

    • Destination setup:

    Limagito file mover destination setup

    limagito file mover win as destination

    limagito file mover windows folder as destination

    #filetransfer #mft #filemanagement

    If you need any info  about this ‘Create an empty file named done’ request, please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team Filters Pascal Script ,
1 4 5 6 7 8 9 10 26
SEARCH