Pascal Script

  • 05 Nov

    How to adjust text in a xml file

    How to adjust text in a xml file

    Q: How can I setup a watch folder for any xml files come in and search for specific wording and change it to another word and move it out to an output directory.

    For the attach example:

    • If you see the word “  <Main>1</Main>”  then change to <Main>Good</Main>
    • If you see other word beside “1” then chang to <Main>NoGood</Main>

    Example content:

    <?xml version=”1.0″?>
    <Header>
    <Main>1</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    A: Yes this is possible using ‘Pascal Script’ as Destination.

    Source is a Windows folder:

    limagito file mover windows folder as source

    We adjusted the ‘Include Filename Filter’ to *.xml because we only want to handle xml files here.

    limagito filemover include filename filter

    We added our ‘Pascal Script’ option as Destination:

    limagito file mover pascal script as destination

    We added the following script. Please do not forget to adjust the ctOutputPath const which must end with a \

    You can download the script: here

    limagito file mover adjust text in a xml file

    RunTime Log result:

    limagito file mover runtime log result

    Content of the 3 source test files we used:

    1. TEST.Good.xml

    <?xml version=”1.0″?>
    <Header>
    <Main>1</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    2. TEST.NoGood.xml

    <?xml version=”1.0″?>
    <Header>
    <Main>0</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    3. TEST.NoGood.blanc.xml

    <?xml version=”1.0″?>
    <Header>
    <Main></Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    Content of the 3 resulting Destination files:

    1. TEST.Good.xml

    <?xml version=”1.0″?>
    <Header>
    <Main>Good</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    2. TEST.NoGood.xml

    <?xml version=”1.0″?>
    <Header>
    <Main>NoGood</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

    3. TEST.NoGood.blanc.xml

    <?xml version=”1.0″?>
    <Header>
    <Main>NoGood</Main>
    <name>Geen</name>
    <Date>221023</Date>
    </Plan>

     

    #xml #filetransfer #filemanagement

    If you need any help with this ‘adjust text in a xml file’ request, please let us know.

    Best Regards,

    Limagito Team

  • 02 Nov

    How to filter files based on reading their content header data

    How to filter files based on reading their content header data

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

    I want is as shown in the picture below.

    filter files based on reading their content header data\filter files based on reading their content header data

    A: In this case the Source must be a Windows folder or share:

    limagito file mover windows folder as source

    Test file inside of: C:\Test\Customer\In\

    limagito fil emover test file example

    Please open our Pascal Script option:

    limagito file mover pascal script option

    Please enable and add the following ‘On Destination’ Pascal Script:

    Var
      iList: Integer;
      tmpCurrentDate, tmpEntry, tmpFile: String;
      tmpList: TStringList;
    Const
      ctRunDate = 'RUNDATE=';
    Begin
      psVSA := '';
      psExitCode:= -2;
      tmpCurrentDate := FormatDateTime('YYYYMMDD', Now);
      tmpFile := psFilePath + psFileName;
      psLogWrite(1, '', 'Searching for RUNDATE inside 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
                If SameText(tmpEntry, tmpCurrentdate) Then
                Begin
                  psExitCode := 1; // Filter found
                  // Debug
                  psLogWrite(1, '', 'Valid RUNDATE found: ' + tmpEntry);
                  // Break
                  Break;
                End;  
              End;
            End;
          End;
         Except
           psLogWrite(1, '', 'LoadFromFileError, ' + tmpFile);
         End;
      Finally
        tmpList.Free;
      End;
    End.

    limagito file mover pascal script option

    We added the following filename include filter because it is important to only process text based files:

    limagito file mover file filter setup

    We added a Windows folder as Destination:

    limagito file mover destination setup

    RunTime Log result:

    limagito file mover runtime log result

    #filehandling #filetransfer #filemanagement

    If you need any help with this ‘filter files based on reading their content header data’ request, please let us know.

    Best Regards,

    Limagito Team

  • 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

1 2 3 4 5 6 7 8 26
SEARCH