Pascal Script

  • 18 Mar

    Strip date from filename filter and move files older than the x days

    Strip date from filename filter and move files older than the x days

    Q: I want to make a file filter-> regex filter able to move files older than the current date -n to another folder.

    The files i question are named like this: hjernetrim-quiz-helside_2025-01-28.pdf (hjernetrim-quiz-helside_yyyy-mm-dd.pdf)

    I can’t figure out how to use the regex Filter. I have no luck with this: hjernetrim-quiz-helside_TCD:[IncDay-5]yyyy-mm-dd:
    Can you help me finding the correct filter syntax?
    A: In this case we are going to strip the date part from the filename and convert it to a Date. Afterwards we’ll compare this with the current date and when older than 5 days we’ll allow the file to be moved. We are not going to use a file filter for this but instead use a little script.
    • First setup your Source, we used a Windows folder as Source:
    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’ script:  link
      • You can adjust the ctOlderThanDays Const if needed. At the moment it is set to 5
    limagito file mover strip date from filename
    • As Destination we used a Windows Folder:

    limagito file mover windows folder as destination

    • RunTime Log Result:

    limagito file mover runtime log result

    If you need any help with this “strip date from filename filter”, please let us know.

    Best Regards,

    Limagito Team

    #managedfiletransfer #filetransfer #filemanagement

  • 08 Dec

    How to email a list of deleted files

    How to email a list of deleted files

    Q: I want to email a list of deleted files on a weekly base. Is this possible with Limagito File Mover.

    A: You could use our ‘Logging to File’ option but in this case the customer wanted a custom list file so we used our scripting option.

    • First you’ll need to setup your delete Rule. We used a Windows Folder as Source:

    limagito file mover Windows folder as source

    • Set Function To ‘Delete Files’:

    limagito file mover list of deleted files

    • Open our ‘Rule Events’ option:

    limagito file mover rule events option

    • Enable ‘On Success’ Event and add the following Pascal Scriptt:
      • do not forget to adjust the ctOutputFile Const
        • We used ‘C:\Test\FileToSend.txt’
    Var
      tmpList: TStringList;
    Const
      ctOutputFile = 'C:\Test\FileToSend.txt';
    Begin
      psExitCode:= 1;
      // ... add your code here
      tmpList := TStringList.Create;
      Try
        Try
          If FileExists(ctOutputFile) Then
            tmpList.LoadFromFile(ctOutputFile)
          Else
            tmpList.Add('Files deleted since ' + FormatDateTime('d mmmm yyyy', Now));          
          // Add Info
          tmpList.Add(FormatDateTime('YYYY/MM/DD HH:NN:SS', Now) + ' Deleted File: ' + psFilePath + psFileName);
          // Save
          tmpList.SaveToFile(ctOutputFile)          
        Except
          psLogWrite(1, '', 'Could not adjust file: ' + ctOutputFile); 
        End;
      Finally
        tmpList.Free;
      End;
    End.

    limagito file mover list of deleted files

    • Next add a second Rule which you’ll trigger once a week. Let the second Rule ‘Move’ the create file ‘C:\Test\FileToSend.txt’ (previously defined inthe script of the delete Rule as ctOutputFile) and use SMTP (email) as Destination.
      • We would use our schedule option to move this listing file once a week
        • The example is set to every Monday at 6:00 AM

    limagito file mover schedule option

    If you need any help with this “list of deleted files” question, please let us know.

    Best Regards,

    Limagito Team

    #managedfiletransfer #filetransfer #filemanagement

  • 06 Dec

    How to add a record to a csv file

    How to add a record to a csv file

    Q: I have a job which is processed through another bit of software, I get 1 file in and at the end of the process, I can have over 100 data files.

    I need to add a record to the start of each file with the same structure, the fields can be empty but I do need to populate 2 of the fields.

    • Sequence fields needs to be 000000
    • Outname fields needs to be the name of the data file

    I then need to add a record at the end of the file but only 1 field needs to be populated

    • Sequence = 999999

    Is this achievable in Limagito? I can do this within the software that processes the data but it will be a very long process to set up.

    A: This should be possible using our scripting option.

    • We used a Windows folder as Source:

    limagito file mover windows folder as source

    • We added the following Include Filename filter because we want to be sure we only are going to handle csv files:

    limagito filemover filename filter

    • As Destination we used our PScript (Pascal Script) option:

    limagito filemover destination setup

    • Please add the following Pascal Script
      • Please add the following script: link
      • Do not forget to adjust the ctOutputPath ( path must end with a \ )
        • This is the path where the adjusted csv files will be saved

    limagito file mover add a record to a csv file

    • Example content of csv source file before changes:

    limagito filemover csv example file

    • Example content of csv destination file after changes:

    limagito file mover example csv file

    Feedback customer:

    You are an absolute legend. Thank you very much

    If you need any help with this “add a record to a csv file” question, please let us know.

    Best Regards,

    Limagito Team

    #csv #managedfiletransfer #filetransfer #filemanagement

    By Limagito-Team CSV Pascal Script ,
1 2 3 4 30
SEARCH