Pascal Script

  • 11 Nov

    Pascal Script Xml Functions added to Limagito File Mover

    Pascal Script Xml Functions added to Limagito File Mover

    We added two extra Pascal Script functions in version v2020.11.11.0.

    • Function psXMLGetAttribute(Const aXML, aRootNode, aChildNode, aAttrName: String): String;
    • Function psXMLSetAttribute(Const aXML, aRootNode, aChildNode, aAttrName, aAttrValue: String): String;

    These functions allow you to Get and Set Xml Attributes. aRootNode or aChildNode can be empty. We prepared the Pascal Script engine to be ready for other Xml requests users may have. Don’t hesitate to ask for extra Xml features.

    We added these functions because we received the following request:

    Currently I have different XML-Files which more or less will have static file contents besides that it would be needed to update one field with the current date of the day. Scheduler will be used and set to run every weekday at approx. 23:59:59.  In the files the XML-field document > date need to be updated in date format YYYY-MM-DD.

    Example for today (2020-11-11):

    <document level=”01-01-xx-xx-xx” date=”2020-11-11″ name=”davinci”>

    Rest of the file contents stays unchanged.

     

    • In the following example will change the value of a node attribute. The Source will be a Xml file (WIN as Source).

    Limagito File Mover WIN as Source

    • The Destination is Pascal Script. The Script will use these new function and write the adjusted Xml content to a new file.

    Limagito File Mover Pascal Script as Destination

    • Don’t forget to adjust the Const ctDest to the path you need the adjusted xml to be saved in.

    Var
      iList: Integer;
      tmpDateStr: String;
      tmpList: TStringList;
      tmpPos: Integer;
      tmpXml: String;
    Const
      ctDest = 'C:\Test\In\Patrick\Out\';
    Begin
      psExitCode:= 0;
      // ... add your code here
      // <!--?xml version="1.0" encoding="ISO-8859-1"?-->
      // 
      // 
      tmpList := TStringList.Create;
      Try
        Try
          // Load Xml File
          psLogWrite(1, '', 'Loading ' + psFilePath + psFileName);
          tmpList.LoadFromFile(psFilePath + psFileName);
          // Prepare Date as String
          tmpDateStr := FormatDateTime('YYYY-MM-DD', Now); // i.e. 2020-11-10
          // Function psXMLGetAttribute(Const aXML, aRootNode, aChildNode, aAttrName): String;
          tmpXml := psXMLGetAttribute(Trim(tmpList.Text), 'document', '', 'date');
          psLogWrite(1, '', 'XML Get Date Attr Value: ' + tmpXML);
          // Function psXMLSetAttribute(Const aXML, aRootNode, aChildNode, aAttrName, aAttrValue: String): String;
          psLogWrite(1, '', 'XML Set Date Attr Valuet ' + tmpDateStr);
          tmpXml := psXMLSetAttribute(Trim(tmpList.Text), 'document', '', 'date', tmpDateStr);
          // Save To File
          // psLogWrite(1, '', 'XML Result: ' + tmpXml);
          tmpList.Text := Trim(tmpXML);
          Try
            tmpList.SaveToFile(ctDest + psFileName);
            psLogWrite(1, '', 'SaveToFile: ' + psFilePath + psFileName + ' Successful');
            // Set Result
            psExitCode:= 1;
          Except
            psLogWrite(1, '', 'SaveToFile:' + psFilePath + psFileName + ' Error');
          End;
        Except
          psLogWrite(1, '', 'LoadFromFile: ' + psFilePath + psFileName + ' Error');
        End;
      Finally
        tmpList.Free;
      End;
    End.

     

    • Original Source Xml file contains a Date attribute with value “2018-11-30”:

    Limagito File Mover Xml Source example

    • The new Destination Xml file contains the adjusted Date attribute with value “2020-11-11”:

    Limagito File Mover Xml Destination Example

    • RunTime log result:

    Limagito File Mover Xml RunTime Log

    If you need any help with these Pascal Script ‘Xml functions’, please let us know.

    Best Regards,

    Limagito Team

    By Limagito-Team Pascal Script XML ,
  • 03 Oct

    Looking for a File Mover Software to accomplish Archiving task

    Q: Looking for Software to accomplish Archiving task.

    Details: Looking for product that we can schedule to look at multiple project folders within a base directory, if no files have been modified in X days within a project folder, then move (copy/delete) that whole project directory and files to another server/CIFS location. Even better if that product can append a string (like date) to the moved project folder for reference ( if possible append 10_02_2020 to end of projectX folder name). Essentially we want to automate archiving data from expensive location/storage to cheap location/storage.

    A: In version v2020.10.3.0 we added some Pascal Script functions to achieve this request.

    What we will do is:
    – Scan base directory for project folders (1 level deep) using Pascal Script
    – Scan each project folder we found for the youngest filedate
    – If youngest filedate in this folder is older than x days then we add this folder to a parameter (%VSA)
    – At the end we provide this parameter (%VSA) as WIN Source. This parameter can containe multiple project folders.
    – The renaming of the Destination will be done in the WIN Destination Setup with a little help of Pascal Script

    Some screenshots to get you started:

    >Please Select WIN as Source and change the ‘Select Directory’ to %VSA.

    So as you see the WIN as Source will NOT be your project base folder! Parameters in LimagitoX File Mover start with %. %VSA stands for Variable String A. %VSA can be used at different places in the rule setup. In this case %VSA will get its value using Pascal Script.


    LimagitoX File Mover WIN as Source

    > Select ‘Pascal Script’ Setup in the ‘Moving Rule’ menu:

    LimagitoX Pascal Script

    >Enable and add the following ‘On Rule Begin’ Pascal Script:

    Important, change the following Const in the Pascal Script:

    • ctSourcePath = ‘C:\Test\In\’;
    • ctOlderThanInDays = 1000;

    ctSourcePath is the base directory of your Project Folders.

    ctOlderThanInDays is set to 1000. So in this case the youngest file should be older then 1000 days before we move the project folder and its content.

    Var
      iPath: Integer;
      tmpFileDate: TDateTime;
      tmpFileName: String;
      tmpPath: String;
      tmpPaths: TStringList;
    Const
      ctSourcePath = 'C:\Test\In\';
      ctOlderThanInDays = 1000;
    Begin
      // Init Var
      psExitCode:= 0;
      psVSA := '';
      // ... add your code here
      psLogWrite(1, '', 'PS Source File Path: ' + ctSourcePath);
      tmpPaths := TStringList.Create;
      Try
        // psListPaths(Directory: String; DirectoryFilter: String; DirectoryLevel: integer; Var Paths: TStringList);
        psListPaths(ctSourcePath, '*', 1, tmpPaths);
        psLogWrite(1, '', 'PS Folders Found: ' + tmpPaths.Text);
        // Iterate
        For iPath := 0 To (tmpPaths.Count-1) Do
        Begin
          tmpPath := tmpPaths.Strings[iPath];
          // psGetYoungestFilename(Directory: String; FilenameFilter: String; IncludeSubDirectory: boolean): String;
          tmpFileDate := psGetYoungestFileDate(tmpPath, '*.*', True);
          If tmpFileDate <> 0 Then
          Begin
            // Debug Info
            tmpFileName := psGetYoungestFilename(tmpPath, '*.*', True);
            psLogWrite(1, '', 'PS Youngest Filename Found: ' + tmpFileName + ' in ' + tmpPath);
            // Check Date
            If tmpFileDate < (Now - ctOlderThanInDays) Then
            Begin
              // Add Patht to psVSA Param
              If psVSA = '' Then
                psVSA := tmpPath + ';'
              Else
                psVSA := psVSA + tmpPath + ';';
            End;
          End;
        End;
        // Debug Info
        psLogWrite(1, '', 'PS Path Count: ' + IntToStr(tmpPaths.Count));
      Finally
        tmpPaths.Free;
      End;
      // Check Result
      If psVSA <> '' Then
      Begin
        psLogWrite(1, '', 'Pascal Script psVSA Result: ' + psVSA);
        psExitCode := 1;
      End
      Else
        psVSA := 'C:\NonExistingPath\';
    End.

    >Enable and add the following ‘On Destination’ Pascal Script

    Important, change the following Const in the Pascal Script:

    • ctSourcePath = ‘C:\Test\In\’;

    ctSourcePath is the base directory of your Project Folders. Must be exactly the same as in the previous ‘On Rule Begin’ Pascal Script.

    This Pascal Script will strip the root part of the Project Folder and set it to %VSB. We’ll use %VSB later for adding the date as requested to the root folder of the project.

    LimagitoX Pascal Script On Destination

    Const
      ctSourcePath = 'C:\Test\In\';
    Begin
      psExitCode:= 1;
      // ... add your code here
      psVSB := psStringReplace(psSourcePath, ctSourcePath, '');
      psVSB := psStringReplace(psVSB, '\', '');
      psLogWrite(1, '', 'psVSB: ' + psVSB);
    End.

    >Select ‘Add WIN’ in the Destination Setup:

    LimagitoX File Mover Select Destination

    >Select your Destination folder (= where to move the project folders to):

    LimagitoX File Mover WIN as Destination

    >Enable and set ‘Create Subdir, opt.’ to:  %VSB_%TCD:MM_DD_YYYY:\%SFS

    LimagitoX File Mover Subdir option

    > Function setup, please leave the Function to ‘Copy Files’ during your tests. If everything is ok then you can change it to ‘Move Files’.

    LimagitoX File Mover Function Setup

    > Done

    If you need any help with this Archiving task setup, please let us know.

    Best Regards,

    Limagito Team

  • 01 Aug

    Q&A 21: Generate a status file for each file which was successfully moved

    Q:  I need to know if a status file can be generated when a file is successfully moved that includes the source location?

    We would like a log file generated called 123456.pdf.log that contains the following data:

    Remote path: C:\upload\input\123456.pdf
    Affinity PDF has been transferred to distiller
    Delivery log name: C:\upload\output\123456.pdf.log

    The remote path is the location where the file was moved from
    The second line is just a text line
    The Delivery Log Name is the location where the file was placed and the name of the log file

    A: Yes this is possible using some Pascal Script.

    Let’s start with the Source. In our example it is a Windows Folder:

    ‘C:\Test\In_PDF\’.

    LimagitoX File Mover Windows Folder as Source

    Important, in the function Setup you need to set the ‘Destination Options’ to ‘Exit Cyclus on Error’. Reason is that we want to be 100% sure that the file was moved before we write the status file.

    LimagitoX File Mover Function Setup

    Destinations Setup, the first destination is the folder where the pdf needs to be moved to. The second destination is the ‘Pascal Script’ needed for the creation of the status file.

    LimagitoX File Mover Destinations

    We added a Windows folder as first Destination. Default Setup is ok.

    LimagitoX File Mover WIN as destination

    The second Destination is our ‘Pascal Script’ needed for the creation of the status file:

    Var
      tmpList: TStringList;
      tmpLogName: String;
      tmpLogPath: String;
    Const
      ctLogRootDir = 'C:\Test\Out\PDF';
    Begin
      tmpLogPath := ctLogRootDir + '%SFS\';
      psExitCode:= 1;
      // ... add your code here    
      tmpList := TStringList.Create;
      Try
        tmpLogName := '%SFN.log';
        Try    
          tmpList.Add('Remote path: %SFP%SFN'); 
          tmpList.Add('Affinity PDF has been transferred to distiller');
          tmpList.Add('Delivery log name: ' + tmpLogPath + tmpLogName);
          // Save
          psLogWrite(1, '', 'SaveToFile: ' + tmpLogPath + tmpLogName);
          tmpList.SaveToFile(tmpLogPath + tmpLogName);   
        Except
          psLogWrite(1, '', 'Log Create Error');
        End;  
      Finally
        tmpList.Free;
      End;  
    End.

    LimagitoX File Mover Pascal Script as Destination

    RunTime Log Result:

    Output Folder Result:

    If you need any help , please let us know.
    Regards,
    Limagito Team
1 19 20 21 22 23 24 25 27
SEARCH