You are not logged in.
Hi and thanks for being here,
I am looking to change many filenames from date-time plus 'index number' using a calculation of 'index number' multiplied by '8' and adding that to the timecode in filename. Files are audio files split at 8-minute, or some number, intervals.
Original filename format - YYYYMMDD_HHMMSS_1. For example:
20200128_204000_1.WAV
20200128_204000_2.WAV
20200128_204000_3.WAV
20200128_204000_4.WAV
Calculation MM + (index multiply by '8')
Result would be
20200128_204000.WAV
20200128_204800.WAV
20200128_210400.WAV (noting max is 59 minutes)
Expert advice on this is greatly appreciated.
Offline
This kind of problem is well suited for the Pascal Script rule. The script below will do the job, as described.
Note that, according to your examples, the adjustment to the minutes is calculated as (Index - 1) * 8, rather than simply Index * 8.
1. Break down the filename into timestamp and index parts.
2. Parse both timestamp and index into proper data types.
3. Adjust the timestamp by (Index - 1) * 8 minutes.
4. Generate new filename from the updated timestamp.
var
IndexStr, TimestampStr: String;
Matches: TWideStringArray;
Timestamp: TDateTime;
Index: Integer;
begin
Matches := SubMatchesRegEx(WideExtractBaseName(FileName), '(\d+_\d+)_(\d+)', False);
if Length(Matches) = 2 then
begin
TimestampStr := Matches[0];
IndexStr := Matches[1];
if TryStrToInt(IndexStr, Index) then
begin
if TryScanDateTime('YYYYMMDD_HHNNSS', TimestampStr, Timestamp) then
begin
Timestamp := IncMinute(Timestamp, (Index - 1) * 8);
FileName := FormatDateTime('YYYYMMDD_HHNNSS', Timestamp) + WideExtractFileExt(FileName);
end;
end;
end;
end.
Offline
Beautiful. I like the parsing to proper date times to make the calculation spill over hour and day. Brilliant. Show me the donation box.
Offline
Show me the donation box.
The option to make a donation is still available, but it has been made somewhat obsolete by the option to purchase a "Pro" version, which unlocks the full potential and supports future development.
Offline