You need a routine like this which mimics Windows file duplication where the first file is 'My File', the second is 'My File (2)', then 'My File (3)' etc.
function AppendDuplicationNumber( const AStr : string ) : string;
// Used to make strings unique
// This examines the string AStr for trailing '(n)' where
// 'n' is an integer.
// If the (n) part is found, n is incremented, otherwise '(2)' is
// appended to the string.
var
iLH, iRH, I : integer;
S : string;
begin
Result := AStr;
iLH := CharPosBackwards( '(', Result );
If iLH > 0 then
begin
iRH := PosEx( ')', Result, iLH );
If iRH > 0 then
begin
I := StrToIntDef( Copy( Result, iLH+1, iRH-iLH-1 ), 0 );
If I > 0 then
begin
Inc(I);
S := IntToStr( I );
Delete( Result, iLH+1, iRH-iLH-1 );
Insert( S, Result, iLH+1 );
Exit;
end;
end;
end;
// Did not increment existing (n), so append it.
Result := Result + ' (2)';
end;