目的是:将当前路径下的内容完整copy,包括copy文件和子目录,子目录内又有文件和子目录。关键是如何遍历该路径下的子目录树。

解决方案 »

  1.   

    uses ShellApi; 用SHFileOperation函数
    转://以下程序在D6+Win98下调试通过
    var
      OpStruc: TSHFileOpStruct;
      frombuf, tobuf: Array [0..MAX_PATH] of Char;
    Begin
      FillChar(OpStruc,sizeof(TSHFileOpStruct),#0);
      FillChar( frombuf, Sizeof(frombuf), #0 );
      FillChar( tobuf, Sizeof(tobuf), #0 );
    //  StrPCopy( frombuf,'C:\temp\temp1'+#0+'C:\temp\temp2'+#0+#0);//error here
      StrPCopy( tobuf, 'C:\music'+#0);
      With OpStruc DO Begin
        Wnd:= 0;
        wFunc:= FO_COPY;
    //    pFrom:= @frombuf;
        pFrom:=PChar('C:\temp\temp1'+#0+'C:\temp\temp2'+#0+#0);//modify here 
        pTo:=@tobuf;
        fFlags:= FOF_NOCONFIRMATION or FOF_NOCONFIRMMKDIR or FOF_ALLOWUNDO;
        fAnyOperationsAborted:= False;
        hNameMappings:= Nil;
        lpszProgressTitle:= Nil;  end;
    if ShFileOperation( OpStruc )=0 then
      showmessage('材料库备份成功!')
    else
      showmessage('材料库备份失败!')
    end;
      

  2.   

    sysu(死树) :
     以上程序实现什麽功能,请解释一下。
      

  3.   

    TSHFileOpStruct是什麽,编译时报错。
      

  4.   

    将'C:\temp\temp1'和'C:\temp\temp2'文件夹下的所有文件(包括子文件夹)拷贝到'C:\music'文件夹中。
      

  5.   

    TSHFileOpStruct是什麽,编译时报错。
      

  6.   

    我上面第一句说了啊,要先在uses 里面加入ShellApi单元。
      

  7.   

    C:\music下为何出现temp1,temp2,能否不出现temp1,temp2,直接是temp1,temp2木录下的内容在C:\music
      

  8.   

    另外如果只对某时间之后的文件copy,该如何处理
      

  9.   

    直接是temp1,temp2木录下的内容可以用'C:\temp\temp1\*.*'。如果只对某时间文件COPY,那得用FindFirst,FindNext函数循环查找然后用CopyFile,具体用法你可以按F1看帮助,里面有例子。