本文整理自网络,侵删。
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》频道 >>