#1 2018-01-30 11:39

StefanR
New Member
Registered: 2017-01-04
Posts: 5

Count one day back

Hello den4b Users!

I have a problem and i was really happy if somebody can help me. I have files with different dates in filename.

on one day:

0131_HSPBXN_P_001
0201_HSPBXN_P_001
0202_HSPBXN_P_001


The first 4 letters is a date. Is there a chance to rename to one day back?
So that the filenames change to:

0131_HSPBXN_P_001 -----> 0130_HSPBXN_P_001
0201_HSPBXN_P_001 -----> 0131_HSPBXN_P_001
0202_HSPBXN_P_001 -----> 0201_HSPBXN_P_001

Thank you for your help!!

Stefan

Offline

#2 2018-01-30 14:30

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 2,625

Re: Count one day back

You can do this with a Pascal Script rule:

const
  YEAR = 2018;
  DAY_OFFSET = -1;
var
  Month, Day: Integer;
  FullDate: TDateTime;
begin
  if TryStrToInt(Copy(FileName, 1, 2), Month) and
     TryStrToInt(Copy(FileName, 3, 2), Day) then
  begin
    FullDate := EncodeDate(YEAR, Month, Day);
    FullDate := IncDay(FullDate, DAY_OFFSET);
    FileName := FormatDateTime('MMDD', FullDate) +
      Copy(FileName, 5, Length(FileName));
  end;
end.

Note the constants at the top of the scripts (YEAR and DAY_OFFSET).

Hopefully, soon, it will be possible to do the same with the Reformat Date rule.

Offline

Board footer

Powered by FluxBB