#1 2023-07-27 02:56

Eric Stiles
Registered: 2023-07-27
Posts: 2

Increment Quarter Dates (4Q2023 to 1Q2024)

To start with I have reviewed several different file renaming programs, and this is the best one.  Its user interface is simple and has almost no learning curve for those of us who just need to do quick and simple renaming of files but at the same time is capable of doing very complex file renaming.  My hat is off to the programmer for such a simple user interface!

Now to my question or comment.  I have to do quarter reports that consist of several different type of files that all have the text 1q2023 someplace in the name.  The 1 is for 1st quarter.  Every quarter I grab the files and copy them to the newest quarter report directory and then rename them.  For example:

1Q2023 Figures Data.xlsx
3 GW Contours 1q2023 - Top.dwg
4 GW Contours 1q2023 - Shallow.dwg

renamed to:

2q2023 Figures Data.xlsx
3 GW Contours 2q2023 - Top.dwg
4 GW Contours 2q2023 - Shallow.dwg

Basically it's bumping up the quarter number to the next quarter and if it's the 4th quarter then it would have to change the quarter number to the 1st quarter but bump up the year to the next year.  For example:  4q2023 would change to 1q2024

I can easily create a "replace" rule that I would just edit each quarter, but I noticed all the different rules that you have and saw the "Reformat Date" rule and thought that maybe it had some date codes for quarters but doesn't seem to. 

Is there a way to do that?

AND PLEASE PLEASE PLEASE DON'T WASTE YOUR TIME ADDING A NEW CODE TO THE DATE CODES.   I was just wondering if there was something quick that I missed in the list of rules.


#2 2023-07-27 10:54

From: den4b.com
Registered: 2006-04-06
Posts: 3,400

Re: Increment Quarter Dates (4Q2023 to 1Q2024)

There is no quarter date formatting variable unfortunately.

However, we can perform this manipulation using the Pascal Script rule in combination with Regular Expressions.

This script will do just that:

  Positions: TIntegerArray;
  Matches: TWideStringArray;
  QuarterNumber, YearNumber: Integer;
  QuarterDelimiter, NewQuarterDate: WideString;
  I, CountMatches: Integer;

  // Find quarter dates
  CountMatches := FindRegEx(FileName, '\b[1-4]Q\d{4}\b', False, Positions, Matches);

  // Iterate through found quarter dates
  for I := 0 to CountMatches-1 do
    // Extract quarter date parts
    QuarterNumber := StrToInt(Copy(Matches[I], 1, 1));
    QuarterDelimiter := Copy(Matches[I], 2, 1);
    YearNumber := StrToInt(Copy(Matches[I], 3, 4));

    // Increment the quarter number
    if QuarterNumber > 4 then
      QuarterNumber := 1;

    // Substitute the updated quarter date
    NewQuarterDate := IntToStr(QuarterNumber) + QuarterDelimiter + IntToStr(YearNumber);
    Delete(FileName, Positions[I], Length(Matches[I]));
    Insert(NewQuarterDate, FileName, Positions[I]);

Note that that the script will ignore quarter dates where the quarter number is not within 1 through 4 range.

P.S. Thank you for your kind feedback, it is the best reward for any devoted software developer!


#3 2023-07-27 18:26

Eric Stiles
Registered: 2023-07-27
Posts: 2

Re: Increment Quarter Dates (4Q2023 to 1Q2024)

Wow, that worked perfectly!  RegEx is not easy for me to quickly create but I've fumbled my way through it in the past, but I've never attempted any Pascal coding.  You are mixing the two!  Amazing! 

Thank you!  I hope you didn't spend a lot of time on this but I do appreciate it.  It's people like you that make everyone else's life a bit easier.  Again, thank you!  You are a god!


Board footer

Powered by FluxBB