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):
- Open our 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.
- Open our Destination setup
- We used a Windows folder as Destination:
- Enable ‘Rename Files during Copy/Move’ and click the ‘Rename Filter Setup’ button:
- Add the following ‘File Rename’ setup:
- RegEx: .{8}(.*)
- Replacement: %VSA\1
- 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