张志峰的博客

水滴石川,积少成多。

导航

Delphi 移动目录

Posted on 2011-12-05 13:49  ╰★张志峰★╮  阅读(475)  评论(0编辑  收藏  举报
 
 
----   3、移动目录  

----   有了拷贝目录和删除目录的函数,移动目录就变得很简单,只需顺序调用前两个函数即可:  

function   MoveDir(sDirName:String;
sToDirName:string):Boolean;
begin
          if   CopyDir(sDirName,sToDirName)   then
                if   RemoveDir(sDirName)   then
                      result:=True
                else
                      result:=false;
end;

///////////////////////////////////////////////
procedure   TForm1.Button2Click(Sender:   TObject);
var
    OpStruc:   TSHFileOpStruct;
    frombuf,   tobuf:   Array   [0..128]   of   Char;
Begin
    FillChar(   frombuf,   Sizeof(frombuf),   0   );
    FillChar(   tobuf,   Sizeof(tobuf),   0   );
    StrPCopy(   frombuf,   'd:\brief\*.* '   );
    StrPCopy(   tobuf,   'd:\temp\brief '   );
    With   OpStruc   DO   Begin
        Wnd:=   Handle;
        wFunc:=   FO_COPY;
        pFrom:=   @frombuf;
        pTo:=@tobuf;
        fFlags:=   FOF_NOCONFIRMATION   or   FOF_RENAMEONCOLLISION;
        fAnyOperationsAborted:=   False;
        hNameMappings:=   Nil;
        lpszProgressTitle:=   Nil;

    end;
    ShFileOperation(   OpStruc   );
end;