Pascal Script

  • 06 Apr

    How to use day of the week folders based on the filename

    Using day of the week folders

    Q: I would like to sort my files based on the filename. The first 8 char contain the date that has to be used. The format is YYYYMMDD (Year = 4 char, Month = 2 char and Day 2 = char).

    A: This is possible using our Pascal Script option. We’ve attached some screenshots to get you started.

    • We used a Windows folder as Source:

    limagito file mover windows folder as source

    • File Filter Setup:

    limagito file mover filename include filter

    • Open our Pascal Script option:

    limagito file mover pascal script option

    • Enable and add the following ‘On Destination’ script:
      • The script will strip the date part from the filename and will check the day of the week
        • Corresponding day of the week will go into the %VSA (Var String A) parameter which will be used in the Destination setup
    Var
      tmpStr: String;
      tmpDate: TDateTime;
      tmpDays: array[1..7] of string;
    Const
      ctDateFormat = 'YYYYMMDD';
      ctDateFormatLen = 8;
      ctDateSeparator = #0;
    Begin
      tmpDays[1] := 'Monday';
      tmpDays[2] := 'Tuesday';
      tmpDays[3] := 'Wednesday';
      tmpDays[4] := 'Thursday';
      tmpDays[5] := 'Friday';
      tmpDays[6] := 'Saturday';
      tmpDays[7] := 'Sunday';
      // Default Result = Skip File
      psExitCode:= 0;
      psVSA := '';
      // ... add your code here
      tmpStr := Copy(psFileName, 1, ctDateFormatLen);
      If StrToIntDef(tmpStr, -1) <> -1 Then
      Begin
        Try
          tmpDate := psStrToDate(tmpStr, ctDateFormat, ctDateSeparator);
          psVSA := tmpDays[DayOfTheWeek(tmpDate)];
          // Successful Result
          psExitCode := 1;
          // Debug
          psLogWrite(1, '', psFileName + ' will go into subfolder: ' + psVSA);
        Except
          psLogWrite(1, '', psFileName + ' conversion exception of date part, file will be skipped');    
        End;
      End
      Else
      Begin
        psLogWrite(1, '', psFileName + ' does not start with a valid date, file will be skipped');
      End;
    End.

    limagito file mover day of the week folders

    • Destination Setup:

    limagito file mover windows folder as destination

    • Important, adjust the default ‘Create Subdir option’, add %VSA (%VSA contains the day of the week):

    limagito file mover day of the week folders

    • RunTime Log Result:

    limagito file mover runtime log

    If you need any help about this ‘day of the week folders’ option, please let us know.

    Best Regards,

    Limagito Team

    #managedfiletransfer #filetransfer #filemanagement #limagito

  • 16 Jan

    How to get week number from filename

    Week number from filename

    Q: I have tried to look at your blog and pascal scripts, but have not found what I am looking for, so maybe you could help.

    I would like to rename files with filename starting with a date to year and two digit week number.
    Example: 18-01-2026-different-names-etc.pdf
    New filename: 202603-different-names-etc.pdf

    A: This is possible using our scriptin option

    • Destination Setup, you need an extra Destination:
      • First Destination must be our Pascal Script
      • Second Destination will be your output

    limagito file mover destination setup

    • Add the following Pascal Script in the First Destination, script: link

    limagito file mover week number from filename

    • Enable and add the following File renaming setup in the Second Destination (= your output directory):

    limagito file mover windows folder as destinationlimagito file mover file renaming setup

    • RunTime Log Result:

    limagito file mover runtime log result

    If you need any help about this ‘week number from filename’ question, please let us know.

    Best Regards,

    Limagito Team

    #basic #managedfiletransfer #filetransfer #filemanagement

    By Limagito-Team Pascal Script Rename
  • 21 Nov

    Send email when Number of files in a folder is higher than 10

    Q: I would like to know how in Limagito to Send email when Number of files in a folder is higher than 10. So, count the number of *.xml files in a specific folder, and simply notify when the number is higher than 10.

    A: Yes, this is possible using our scripting option

    • As Source we used our PScript option and added the following script:
      • Do not forget to adjust the Const values
        • ctSourcePath, ctFilter, ctIncludeSubDir and ctFileCount
      • Add the following script
        • If count of files > 10 than this will trigger the On Success Rule Event (psExitCode = 1)
    Var
      tmpCount: Integer;
    Const
      ctSourcePath = 'C:\Test\In_Xml\';
      ctFilter = '*.xml';
      ctIncludeSubDir = True;
      ctFileCount = 10;
    Begin
      psExitCode:= 0;
      // ... add your code here
      tmpCount := psCountFiles(ctSourcePath, ctFilter, ctIncludeSubDir);
      If tmpCount > ctFileCount Then
      Begin
        psLogWrite(1, '', 'File Count: ' + IntToSTr(tmpCount) + ', more than ' + IntToStr(ctFileCount));
        psExitCode := 1;
      End;
    End.

    limagito file mover number of files in a folder

    • Next add the On Success Rule Event

    limagito filemover on success rule event

    • Do not forget to enable the option ‘Enable On Success Events for LimagitoX temporary Files’.
      • This is needed because in this case we don’t have any Destination.

    limagito file mover on success rule event options

    • Result email:

    Send email when Number of files in a folder is higher than 10

    If you need any help about this request, please let us know.

    Best Regards,

    Limagito Team

    #managedfiletransfer #filetransfer #filemanagement

     

     

1 2 3 4 32
SEARCH