The batch script still works fine unless the headline contains the ' (single quote) character when it gives a syntax error at 37,113. This is due to the string '%ImageName' but I don't know how to fix it as %ImageName isn't a 'real' variable. Anyone know how to fix this?
Code: Select all
const
StartNumber = 1; // First Image Number
NumberLength = 3; // Number of digits in number string
var
FileNameNoNumber: String; // The filename based on headline using no unique number extension
function IsNonImage (AFilename: String): Boolean;
var
AExt: String;
begin
result := False;
AExt := UpperCase (ExtractFileExt (AFileName));
case AExt of
'.THM', '.XMP':
result := True;
end;
end;
function IncrementFileNumber: Integer;
var
FileNumber: Integer;
FileName: String;
begin
if IsNonImage (ImageItem.Filename) then begin
// Use the number of the last image
result:= ReadFromRegistry ('Scripts\IncFileNumber', 'LastNum', StartNumber);
end else begin
FileNumber:=StartNumber-1;
// Find the next nonexisting filename
repeat
FileNumber:=FileNumber+1;
FileName:= IncludeTrailingBackslash(ImageItem.FilenamePath) + AnsiReplaceStr('%ImageName','/','_') + ' (' + AddLeadingChars (IntToStr(FileNumber), '0', NumberLength, False) + ')' + ImageItem.FilenameExtension;
until FileExists(FileName)=False;
WriteToRegistry ('Scripts\IncFileNumber', 'LastNum' , FileNumber);
result:=FileNumber;
end;
end;
// Is there a headline?
if length('%ImageName')=0 then begin
// No. Keep filename
result:=ImageItem.Filename;
end else begin
result:= AnsiReplaceStr('%ImageName','/','_') + ' (' + AddLeadingChars (IntToStr(IncrementFileNumber), '0', NumberLength, False) + ')' + ImageItem.FilenameExtension;
end;