土办法但是很有用,在程序里直接调用 DOS 命令:Shellexecute("open"....."start copy xxx\xxx\*.* xxx\xxx\*.*")简单吧?其实有些东西用命令行完全可以完成,为什么又何苦让自己写一个 "copy"命令呢?

解决方案 »

  1.   

    我这招是在Linux 下给命令行程序写 GUI 时学来的,原来也不知道“原来事情很简单”
    :P
      

  2.   

    看这个帖子吧,上面有全部的代码:http://www.csdn.net/expert/topic/797/797021.xml?temp=.9084284
      

  3.   

    很久以前写的一段代码, 能用得上就用吧.type 
      TFunc = (COPY, MOVE, DELETE, RENAME);
    {...}procedure TForm1.FileOperation(SrcFileName: PChar; DestFileName: PChar; AFunc: TFunc);
    var
      FileOp: SHFILEOPSTRUCT;
      I: Integer;
    begin
      FileOp.Wnd := Self.Handle;
      FileOp.pFrom := SrcFileName;       // 可以是文件名或者目录名.
      FileOp.pTo := DestFileName;         
      FileOp.fFlags := FOF_ALLOWUNDO;
      FileOp.fAnyOperationsAborted := true;
      FileOp.hNameMappings := nil;
      FileOp.lpszProgressTitle := nil;  case AFunc of            
        COPY: FileOp.wFunc := FO_COPY;
        MOVE: FileOp.wFunc := FO_MOVE;
        DELETE: FileOp.wFunc := FO_DELETE;
        RENAME: FileOp.wFunc := FO_RENAME; //重命名已经由其他过程处理了.
      end;
      
      SHFileOperation(FileOp);
    end;
      

  4.   

    ////例如:xcopy('c:\windows','c:\windows.cpy');
    procedure xcopy(source: string;dest:string);
    var
      sr: TSearchRec;
    const
      fileattrs=63;
    begin
      try
         mkdir(dest);
      except
      end;
      source:=source+'\*.*';
      if FindFirst(source, fileattrs, sr) = 0 then
      begin
          if (sr.Name <>'.') and (sr.name<>'..') then
          begin
            if ((sr.attr and fadirectory)=fadirectory)  then
                    xcopy(extractfilepath(source)+sr.name,dest+'\'+sr.name)
            else
                  begin
                      copyfile(pchar(extractfilepath(source)+sr.name),pchar(dest+'\'+sr.name),false);
                      if strToFloat(form1.Edit3.Text)<>0 then
                      begin
                      dodo:=0;
                      Form1.Timer1.Enabled :=true;
                      while dodo=0 do
                      begin
                            Application.ProcessMessages;
                      end;
                      Form1.Timer1.Enabled :=false;
                      end;
                  end;
          end;
          while FindNext(sr) = 0 do
          begin
            if  (sr.Name <>'.') and (sr.name<>'..') then
            begin
            if ((sr.attr and fadirectory)=fadirectory)  then
                    xcopy(extractfilepath(source)+sr.name,dest+'\'+sr.name)
            else
                 begin
                     copyfile(pchar(extractfilepath(source)+sr.name),pchar(dest+'\'+sr.name),false);
                     if strTofloat(form1.Edit3.Text)<>0 then
                     begin
                     dodo:=0;
                     Form1.Timer1.Enabled :=true;
                     while dodo=0 do
                     begin
                            Application.ProcessMessages;
                     end;
                     Form1.Timer1.Enabled :=false;
                     end;
                 end;
            Application.ProcessMessages ;
            end;
          end;
          FindClose(sr);  end;end;
      

  5.   

    Rx包里有一大堆File,String,Control等的代码,直接调用就可以了,呵呵,很方便的
      

  6.   

    copy file *.* to c:\ 
    Foxpro好方便
      

  7.   

    {文件拷备函数   需在Uses加入FileCtrl和ShellAPI}
    {最后修改时间:17:07 2002-04-03  整理:刘红军}function TForm1.WinCOPY(File_name:string;File_name_S:string):string;
    var
      OpStruc:TSHFileOpStruct;
      FromBuf,ToBuf:Array[0..128] of Char;
    begin
          FillChar(FromBuf,Sizeof(FromBuf),0);
          FillChar(ToBuf,Sizeof(ToBuf),0);
         //用0初始化FromBuf和ToBuf数组
          StrPCopy(FromBuf,Pchar(File_name));
          StrPCopy(ToBuf,Pchar(File_name_S));
         //分别在 FromBuf和ToBuf数组中填入操作的源目录及目标目录
         //开始填充OpStruc记录
        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;
         OpStR:= SHFileOperation(OpStruc);
    end;