var
Buf: TStringList;
i: Integer;
S, s1, sName, sExt: AnsiString;
begin
sExt := '.txt';
sName := 'NewFile';
s := sName + sExt;
i := 1;
try
Buf := TStringList.Create;
if FileExists(s) then
begin
begin
s1 := sName + '(' + inttostr(i) + ')' + sExt;
while FileExists(s1) do
begin
Inc(i);
s1 := sName + '(' + inttostr(i) + ')' + sExt;
end;
end;
begin
Buf.SaveToFile(s1);
end;
end
else
begin
Buf.SaveToFile(s);
end;
finally
FreeAndNil(Buf);
end;
end;