創建文件1

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;

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