重命名文件 或文件夹

默认的重命名是这样的
MoveFile(PChar('C:\1.txt'),PChar('C:\ABC.txt'));
    
现在修改成这样的
__RenameFile('C:\1.txt','abc');//重命名文件
 
    
//重命名文件 或文件夹
function __RenameFile(OldName:string;Title:string):Boolean;
var
    NewName:string;
begin
  NewName:= Format('%s%s%s',[ExtractFilePath(OldName),Title,ExtractFileExt(OldName)]);
  Result:=MoveFile(PChar(OldName), PChar(NewName));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
    if not __RenameFile('C:\tree.txt','TreeView') then
        Application.MessageBox('重命名文件失败','重命名',MB_ICONERROR);
end;




posted @ 2013-07-01 18:13  XE2011  阅读(259)  评论(0编辑  收藏  举报