You are not logged in.
Pages: 1
Hello,
I'm using the increment serial number to rename the files. It's ok.
My problem is:
If my destination folder already has some files with serialized numbers, Is it possible to start automatically the serial number with the next number?
If someone can help me, I'm very thankful for it.
Thank you
Offline
There are a couple of options, but you haven't provided a bare minimum example to help figure out what might work.
Generally speaking...
Option 1: Add all files, already serialized and not yet serialized files, re-serialize all files.
Option 2: Use Pascal Script rule to automatically figure out the last serial number used and use it for further serialization.
Offline
Sorry, see example below:
I renamed these files:
AFK2700001.con
AFK2700002.con
AFK2700003.con
And I used these files and clean the files list in the program.
In another moment, I need to rename new files, so, I would like to start to rename serial number (automatically) from the last serial number used.
AFK2700004.con
AFK2700005.con
AFK2700006.con
Unfortunatelly, I don't know to create Pascal Script rule.
Thank you.
Offline
The script below will find the greatest trailing serial number from files in a folder defined by Directory constant, and will use that serial number for naming the new files in ReNamer.
const
Directory = 'C:\Temp\Serial';
Mask = '*.*';
function ExtractTrailNumber(const Text: String): Int64;
var
I: Integer;
Number: String;
begin
Number := '';
for I := Length(Text) downto 1 do
begin
if Pos(Text[I], '0123456789') > 0 then
Number := Text[I] + Number
else
Break;
end;
if Length(Number) > 0 then
Result := StrToInt64(Number)
else
Result := -1;
end;
function DetermineLastSerial: Int64;
var
I: Integer;
Files: TWideStringArray;
Serial: Int64;
begin
Result := 0;
WideScanDirForFiles(Directory, Files, False, False, False, Mask);
for I := 0 to Length(Files) - 1 do
begin
Serial := ExtractTrailNumber(WideExtractBaseName(Files[I]));
if Serial > Result then
Result := Serial;
end;
end;
var
Initialized: Boolean;
CurrentSerial: Integer;
begin
if not Initialized then
begin
Initialized := True;
CurrentSerial := DetermineLastSerial;
end;
CurrentSerial := CurrentSerial + 1;
FileName := Int64ToStr(CurrentSerial) + WideExtractFileExt(FileName);
end.
Offline
It worked out!
Thank you
Offline
Pages: 1