如何复制文件夹到另外一个文件夹里?希望有代码或者实例,谢谢

解决方案 »

  1.   

    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;
      

  2.   

    http://www.delphibbs.com/delphibbs/dispq.asp?lid=144910
    参考
      

  3.   


    function CopyDir(sDirName:String;
    sToDirName:String):Boolean;
    var
     hFindFile:Cardinal;
     t,tfile:String;
     sCurDir:String[255];
     FindFileData:WIN32_FIND_DATA;
    begin
     //先保存当前目录
     sCurDir:=GetCurrentDir;
     ChDir(sDirName);
     hFindFile:=FindFirstFile('*.*',FindFileData);
     if hFindFile< >INVALID_HANDLE_VALUE then
     begin
        if not DirectoryExists(sToDirName) then
         ForceDirectories(sToDirName);
        repeat
           tfile:=FindFileData.cFileName;
           if (tfile='.') or (tfile='..') then
            Continue;
           if FindFileData.dwFileAttributes=
           FILE_ATTRIBUTE_DIRECTORY then
           begin
             t:=sToDirName+''+tfile;
             if not DirectoryExists(t) then
               ForceDirectories(t);
             if sDirName[Length(sDirName)]< >'' then
               DoCopyDir(sDirName+''+tfile,t)
             else
               DoCopyDir(sDirName+tfile,sToDirName+tfile);
           end
           else
           begin
             t:=sToDirName+''+tFile;
             CopyFile(PChar(tfile),PChar(t),True);
           end;
        until FindNextFile(hFindFile,FindFileData)=false;
        FindClose(hFindFile);
     end
     else
     begin
        ChDir(sCurDir);
        result:=false;
        exit;
     end;
     //回到原来的目录下
     ChDir(sCurDir);
     result:=true;
    end;
      

  4.   

     CopyFile('c:\BOOTLOG.TXT', 'c:\temp\BOOTLOG.TXT', True);
      

  5.   

    以前有个类似的帖子http://topic.csdn.net/t/20011126/09/388329.html
      

  6.   


    CopyFile也可复制文件夹
    使用TSHFileOpStruct吧,可以调用windows本身的拷贝操作,带提示,带进度