Rename

  • 08 Sep

    Query around filename to directory name

    Q: Query around filename to directory name. Reaching out just in case you have an easy way to assist for this one:

    We have a rule which currently picks up files from a SFTP source and drops them into an S3 bucket.

    Here are a sample of the source filenames:

    • (64506930) 87268700 20230826.pdf
    • (64506930) 87268701 20230826.pdf
    • (568454) 87282612 20230831.pdf

    This works, however we would like to drop them into a folder based on the {accountId} which is between the brackets:

    filename to directory name

    However we can’t rely on the filename begin and end positions as the accountId isn’t always the same length.

    Is there an easy answer to use a regex or something to select the accountId from between the brackets?
    Please let me know if you have any queries.

    A: In your Destination setup please adjust the ‘Create Subdir option’ to:   %SFN

    limagito file mover destination subdirectory option

    • Enable ‘Rename Destination Subdirectory’ and open ‘Rename Filter Setup’

    limagito file mover rename directory option

    • Directory Renaming Setup:
      RegEx:  \((.*)\)(.*)
      Replacements:   user/\1/invoices/

    filename to directory name

    • RunTime Log Result:

    limagito file mover runtime log result

    • Feedback Customer:

    Just a quick email to say thank you!  I only reach out to support occasionally – and each time I’m surprised at the level of support provided.

    If you need any info about this ‘filename to directory name’ request, please let us know.

    #mft #filetransfer #filemanagement

    Best regards,

    Limagito Team

    By Limagito-Team Rename
  • 29 Jun

    How to increment the date in a filename by plus one day

    Q: Is it possible to rename a file containing a date string when copying it to increment the date in the filename by plus one day?

    where yyyymmddxx_I.p1.pdf the yyyymmdd will increase by +1

    Examples

    • Input: 2022010501_I.p1.pdf
      • Output: 2022010601_I.p1.pdf
    • Input: 2023123101_I.p1.pdf
      • Output: 2024010101_I.p1.pdf

    A: Yes this is possible. Please have a look at the following screenshots.

    • We used a Windows folder as Source (can be any other type of Source too):

    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’ Pascal Script:
    Var
     tmpFilename, tmpDateStr: String;
     tmpDate: TDateTime;
    Const
      ctDateFormatOld = 'YYYYMMDD'; ctDateSepOld = #0;
      ctDateFormatNew = 'YYYYMMDD';
    Begin
    (*
    Example:
    Input: 2022010501_I.p1.pdf
    Output: 2022010601_I.p1.pdf
    *)
      psExitCode:= 0;
      // ... add your code here
      tmpFilename := psFilename;
      If length(tmpFilename) >= 8 Then
      Begin
        Try
          tmpDateStr := Copy(tmpFilename, 1, Length(ctDateFormatOld));
          tmpDate := psStrToDate(tmpDateStr, ctDateFormatOld, ctDateSepOld);
          tmpDate := psIncDay(tmpDate, 1);
          psVSA := FormatDateTime(ctDateFormatNew, tmpDate);
          psExitCode:= 1;
        Except
          psLogWrite(1, '', 'Strip Date from File exception on ' + psFilePath + psFilename);
        End;
      End
      Else
      Begin
        psLogWrite(1, '', 'Strip Date length of File error on ' + psFilePath + psFilename);
      End;
    End.

    limagito file mover pascal script setup

    • Open our Destination setup

    limagito file mover destination setup

    • We used a Windows folder as Destination:

    limagito file mover windows folder as destination

    • Enable ‘Rename Files during Copy/Move’ and click the ‘Rename Filter Setup’ button:

    limagito file mover file rename option

    • Add the following ‘File Rename’ setup:
      • RegEx:  .{8}(.*)
      • Replacement:  %VSA\1

    limagito file mover file rename setup

    • RunTime Log result:

     

    limagito file mover runtime log result

    #mft #Filetransfer #rename

    If you need any info about this “increment the date in a filename” request, please let us know.

    Best regards,

    Limagito Team

  • 24 Apr

    File renaming logic using day of week function

    Q: We need the dates tv listing dates moved to publications dates. This newspaper publishes 3 days a week, Wednesday, Friday and Saturday. In order to automatically flow the graphic onto the page, the file name needs to match the publication date.

    We need the following logic,

    • Wednesday graphic gets Wednesday date,
    • Thursday graphic gets Wednesday date (the day before)
    • Friday graphic gets Friday date
    • Saturday graphic gets Friday date (the day before)
    • Sunday / Monday / Tuesday graphics get the previous Saturday date.

    For example:

    Sunday / Monday / Tuesday dates:

    • PH_20230423.pdf
    • PH_20230424.pdf
    • PH_20230425.pdf

    We’d want renamed to

    • PH_Sun_20230422.pdf
    • PH__Mon_20230422.pdf
    • PH_Tues_20230422.pdf

    Technically the “Sun”, “Mon”, “Tues” could be anything as long as they’re unique and predictable.

    Moving onto the next set:

    • PH_20230426.pdf
    • PH_20230427.pdf

    Would be renamed to

    • PH_Wed_20230426.pdf
    • PH_Thurs_20230426.pdf

    And finally:

    • PH_20230428.pdf
    • PH_20230429.pdf

    Would be renamed to

    • PH_Fri_20230428.pdf
    • PH_Sat_20230428.pdf

     

    A: Yes this is possible using our Mover Pascal Script and Destination RegEx renaming options.

    • Open ‘Pascal Script’ setup

    Limagito File Mover Pascal Script

    • Enable and add the following ‘On Destination’ Pascal Script:
    Var
      tmpLen: Integer;
      tmpDateStr, tmpFilePart: String;
      tmpDate1, tmpDate2: TDateTime;
    Begin
      psExitCode:= 1;
      // ... add your code here
      // PH_20230423.pdf > PH_Sun_20230422.pdf
      tmpDateStr := psFileName;
      tmpDateStr := psStringReplace(tmpDateStr, '.pdf', '');
      tmpLen := Length(tmpDateStr);
      If tmpLen >= 8 Then
      Begin
        tmpDateStr := Copy(tmpDateStr, tmpLen - 8 + 1, 8);
        tmpDate1 := psStrToDate(tmpDateStr, 'YYYYMMDD', #0);
        Case DayOfWeek(tmpDate1) of
        1: // Sunday
          tmpDate2 := psIncDay(tmpDate1, -1);
        2: // Monday
          tmpDate2 := psIncDay(tmpDate1, -2);
        3: // Tuesday
          tmpDate2 := psIncDay(tmpDate1, -3);
        4: // Wednesday
          tmpDate2 := tmpDate1;
        5: // Thursday
          tmpDate2 := psIncDay(tmpDate1, -1);
        6: // Friday
          tmpDate2 := tmpDate1;
        7: // Saturday
          tmpDate2 := psIncDay(tmpDate1, -1);
        Else
          psExitCode := 0; // Error
        End;
        psVSA := FormatDateTime('DDD', tmpDate1);
        psVSB := FormatDateTime('YYYYMMDD', tmpDate2);
        psLogWrite(1, '', 'Date: ' + psVSB + ', Day: ' + psVSA);
      End
      Else
        psLogWrite(1, '', 'Length error of ' + tmpDateStr);
    End.

    Limagito File Mover Pascal Script Day of Week

    • Afterwards, adjust the File Rename option in your Destination setup:
    RegEx:  (.*)_(.*)\.(.*)
    Replacement:  \1_%VSA_%VSB.\3
    Limagito File Mover File Rename using RegEx
    – RunTime Log Result:
    Limagito File Mover RunTime Log

    #FileTransfer

    If you need any info about this  ‘day of week function’, please let us know.

    Best regards,

    Limagito Team

1 2 3
SEARCH