[delphi函数]RenameFile 文件改名
2009-12-04 22:17 HYrz的菜园子 阅读(1156) 评论(0) 编辑 收藏 举报
//文件改名 RenameFile
var
OldName,NewName: string;
begin
OldName := 'c:\temp\Old.txt';
NewName := 'c:\temp\New.txt';
var
OldName,NewName: string;
begin
OldName := 'c:\temp\Old.txt';
NewName := 'c:\temp\New.txt';
if RenameFile(OldName,NewName) then
ShowMessage('改名成功!');
//也可以:
SetCurrentDir('c:\temp');
OldName := 'Old.txt';
NewName := 'New.txt';
if RenameFile(OldName,NewName) then
ShowMessage('改名成功!');
end;
=====================
function RenameFile(const OldName, NewName: string): Boolean;
begin
{$IFDEF MSWINDOWS}
Result := MoveFile(PChar(OldName), PChar(NewName));
{$ENDIF}
{$IFDEF LINUX}
Result := __rename(PChar(OldName), PChar(NewName)) = 0;
{$ENDIF}
end;