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获取注册表run下所有值

crc32.pas

Delphi 一个高效的正整数排序函数

Delphi 调试tms web core应用

Delphi 压缩带密码的access数据库的方法

Delphi著名皮肤控件库大全评测

Delphi tthread中文注释

使用Delphi启动和关闭外部应用程序

Delphi 脉搏波9808血压计读取测试程序

Delphi根据进程pid等待进程结束或者结束进程

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



打赏

取消

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

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

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

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

评论

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