File Mover Blog

June 29, 2023

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

By Limagito-Team Pascal Script Rename Share:
SEARCH