delphi MakeUniqueFileName 创建文件名如果已经存在自动更改文件名  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.073456048965454 seconds