delphi MakeUniqueFileName 创建文件名如果已经存在自动更改文件名


本文整理自网络,侵删。

 
var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  ShlObj;

function MakeUniqueFileName( const APath, AFileName: string ): string;
var
  UniqueName: array[0..MAX_PATH-1] of Char;
begin
  Result := IncludeTrailingPathDelimiter(APath) + AFileName;

  if FileExists( Result ) then
    if PathMakeUniqueName( UniqueName, Length(UniqueName), PChar(AFileName), nil, PChar(APath) ) then
      Result := UniqueName;
end;




procedure TForm1.Button1Click(Sender: TObject);
var
  FileName: string;
begin
  FileName := MakeUniqueFileName( 'D:\', '123.txt' );  // 如果 123.txt存在 则 123(1).txt

  ShowMessage( FileName );

end;

来源:http://yypbd.tistory.com/1350?category=401325

相关阅读 >>

Delphi windows 编程[15] - 菜单消息: wm_command

Delphi olevariant excel保存文件

Delphi循环遍历同类控件或所有控件

Delphi获取ie路径

Delphi 关于 "高位" 与 "低位"

Delphi datasnap的线程池

Delphi从trichedit获得rtf格式文本

Delphi 2010下使用sqlitesimpleDelphi连接sqlite数据库及中文乱码问题的解决

devexpress vcl 动态调用皮肤

Delphi firedac 获取 insert 记录的自增 id

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...