創建文件2

var
  Buf: TStringList;
  i: Integer;
  S, s1, sName, sExt: AnsiString;
begin
  sExt := '.txt';
  sName := 'NewFile';
  s := sName + sExt;
  i := 0;
  try
    Buf := TStringList.Create;
    if FileExists(s) then
    begin
      repeat
        Inc(i);
        s1 := Format('%s%d%s', [sName+'(', i, ')'+sExt]);
      until
        not FileExists(s1, True);
      Buf.SaveToFile(s1);
    end
    else
      Buf.SaveToFile(s);
  finally
    FreeAndNil(Buf);
  end;
end;

發佈了216 篇原創文章 · 獲贊 15 · 訪問量 39萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章