- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
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