"Days Span" Pascal Script Needed for RENAMER tool

I have a few thousand jpg files and I have them named by the EXIF Date of the camera, using a tool called "ReNamer" (http://www.den4b.com/downloads.php?project=ReNamer).

So my files are named in the format 'yyyymmddhhmmss'

Example:

20090521021518.jpg
20090522072110.jpg
and so on...

The problem is that my camera, the date was set one day LATER than the ACTUAL day, so in reality, the above should actually be:

20090520021518.jpg (i.e. May 20)
20090521072110.jpg (i.e. May 21)
and so on...

ReNamer is pretty slick and had a pre-existing pascal script called "Hours Span" which I tweaked to something like the code attached, and it worked beautifully. I did this to change the hours of the of the same files. Sadly it didn't have a built-in "Days Span" pascal script.

I was wondering if anyone here could help me out with a "Days Span" pascal script. Again, I've attached the code snippet of the "Hours Span" with this thread as a reference.

Also, I've attached ReNamer's help guide (pdf) if needed.

Thanks.


// This HoursSpan script reads dates from filenames in format: yyyymmddhhnnss.JPG
// then adds/subtracts N hours from the date and prints the new date in the
// format defined by DateOutputFormat variable. HoursSpan variable defines
// how many hours should be added/subtracted (use minus for subtraction).
 
const
  HoursSpan = -1;   // amount of hours to add or subtract!!
  DateOutputFormat = 'yyyymmddhhnnss';  // output date format!!
  HoursPerDay = 24;  // do not change this!!
 
var
  iYear, iMonth, iDay, iHour, iMin, iSec: Integer;
  Date, Time, DateTime: TDateTime;
 
procedure AddHours(var ADateTime: TDateTime; const ANumberOfHours: Integer);
begin
  ADateTime := ((ADateTime * HoursPerDay) + ANumberOfHours) / HoursPerDay;
end;
 
begin
  // extract date-time variables as integers
  iYear  := StrToIntDef(Copy(FileName, 1, 4), -1);
  iMonth := StrToIntDef(Copy(FileName, 5, 2), -1);
  iDay   := StrToIntDef(Copy(FileName, 7, 2), -1);
  iHour  := StrToIntDef(Copy(FileName, 9, 2), -1);
  iMin   := StrToIntDef(Copy(FileName, 11, 2), -1);
  iSec   := StrToIntDef(Copy(FileName, 13, 2), -1);
 
  // process only if all variables are correctly converted
  if (iYear >= 0) and (iMonth >= 0) and (iDay >= 0) and
     (iHour >= 0) and (iMin >= 0) and (iSec >= 0) then
 
  begin
    // create a new date-time variable
    Date := EncodeDate(iYear, iMonth, iDay);
    Time := EncodeTime(iHour, iMin, iSec, 0);
    DateTime := Date + Time;
 
    // add hours (use minus for subtracting)
    AddHours(DateTime, HoursSpan);
 
    // concatenate the rest of the filename and the new date
    FileName := Copy(FileName, 20, Length(FileName));
    FileName := FormatDateTime(DateOutputFormat, DateTime) + FileName;
  end
 
  // something went wrong
  else FileName := 'INVALID INPUT';
end.

Open in new window

User-Manual.pdf
LVL 1
super786Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JosephGloszCommented:
this should do.  Since the rest of the code works well, as you say, we'll simply reuse as much of it as we can.  Here, we are adding a procedure called AddDays and it'll hook into the rest of the code.

const
  HoursSpan = -1;   // amount of hours to add or subtract!!
  DateOutputFormat = 'yyyymmddhhnnss';  // output date format!!
  HoursPerDay = 24;  // do not change this!!
  DaysSpan = -1;

var
  iYear, iMonth, iDay, iHour, iMin, iSec: Integer;
  Date, Time, DateTime: TDateTime;
 
procedure AddHours(var ADateTime: TDateTime; const ANumberOfHours: Integer);
begin
  ADateTime := ((ADateTime * HoursPerDay) + ANumberOfHours) / HoursPerDay;
end;
 
procedure AddDays(var ADateTime: TDateTime; const ANumberOfDays: Integer);
begin
  AddHours(ADateTime,ANumberOfDays*HoursPerDay);
end;
 
begin
  // extract date-time variables as integers
  iYear  := StrToIntDef(Copy(FileName, 1, 4), -1);
  iMonth := StrToIntDef(Copy(FileName, 5, 2), -1);
  iDay   := StrToIntDef(Copy(FileName, 7, 2), -1);
  iHour  := StrToIntDef(Copy(FileName, 9, 2), -1);
  iMin   := StrToIntDef(Copy(FileName, 11, 2), -1);
  iSec   := StrToIntDef(Copy(FileName, 13, 2), -1);
 
  // process only if all variables are correctly converted
  if (iYear >= 0) and (iMonth >= 0) and (iDay >= 0) and
     (iHour >= 0) and (iMin >= 0) and (iSec >= 0) then
 
  begin
    // create a new date-time variable
    Date := EncodeDate(iYear, iMonth, iDay);
    Time := EncodeTime(iHour, iMin, iSec, 0);
    DateTime := Date + Time;
 
    // add hours (use minus for subtracting)
    // AddHours(DateTime, HoursSpan);

    AddDays(DateTime, DaysSpan);
 
    // concatenate the rest of the filename and the new date
    FileName := Copy(FileName, 20, Length(FileName));
    FileName := FormatDateTime(DateOutputFormat, DateTime) + FileName;
  end
 
  // something went wrong
  else FileName := 'INVALID INPUT';
end.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
super786Author Commented:
Unbelievably flawless!

Thank you.

I do realize now that I have a follow - up. Would you prefer I post in this thread, or create a new question? I'm fine either way.
0
JosephGloszCommented:
No, a followup here is fine. I'll help if I can!
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

super786Author Commented:
0
super786Author Commented:
Need more coffee...sent you the wrong url.

This is the one with the follow-up: http://www.experts-exchange.com/Programming/Languages/Pascal/Free_Pascal/Q_24440227.html
0
JosephGloszCommented:
since there is more to the question than I thought, I answered it in the other thread...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Pascal

From novice to tech pro — start learning today.