// This script reads dates from filenames in format: yyyy-mm-dd hh-nn-ss.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 = -5; // amount of hours to add or subtract!! DateOutputFormat = 'yyyy-mm-dd hh.nn.ss'; // output date format!! HoursPerDay = 24; // do not change this!! var iYear, iMonth, iDay, iHour, iMin, iSec: Integer; Date, Time, DateTime: TDateTime; ExifTag: String; begin ExifTag := CalculateMetaTag(FilePath, ':EXIF_Date:'); // extract date-time variables as integers iYear := StrToIntDef(Copy(ExifTag, 1, 4), -1); iMonth := StrToIntDef(Copy(ExifTag, 6, 2), -1); iDay := StrToIntDef(Copy(ExifTag, 9, 2), -1); iHour := StrToIntDef(Copy(ExifTag, 12, 2), -1); iMin := StrToIntDef(Copy(ExifTag, 15, 2), -1); iSec := StrToIntDef(Copy(ExifTag, 18, 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) DateTime:= IncHour(DateTime, HoursSpan); // concatenate the rest of the filename and the new date FileName := FormatDateTime(DateOutputFormat, DateTime) + WideExtractFileExt(FileName); end // something went wrong else FileName := 'INVALID INPUT'; end. |