1.如何把‘c:\me\you’下的所有文件COPY到‘d:\me\you’
2.如何把‘c:\me\you’下的指定的文件 one.db,two.txt  COPY到‘d:\me\you’
要先检查目标文件夹是否存在,不存在先建立,再COPY

解决方案 »

  1.   

    我是说在软件内,用DELPHI代码实现啊,兄弟
      

  2.   

    function CopyFileTo(const Source: string; const Destination: string): Boolean;记得它可以Copy文件夹。
      

  3.   

    API SHFileOperation
    Uses ShellAPI;See MSDN or Win32 SDK for more infosearch in web you can also find the answer
      

  4.   

    就是用Copy函数即可,多个文件,循环调用即可。
      

  5.   

    直接调用dos的xcopy命令
    winexec('xcopy c:\me\you d:\me\you’,SW_HIDE);
    xcopy有很多选项,可参考一下,用该命令当目的目录不存在时会自动创建
      

  6.   

    提供一个思路,利用API函数CopyFile或者CopyFileEx都行:
    function CopyFile(lpExistingFileName, lpNewFileName: PChar; bFailIfExists: BOOL): BOOL;
    这里是个单个文件拷贝的例子:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      Path: String;
    begin
      Path := ExtractFilePath(Application.ExeName);
      CopyFile(PChar(Path + 'a.txt'), PChar(Path + 'Received\b.txt'), False);
    end;
    相关函数可以参考MSDN里面的CopyFileEx、MoveFile、MoveFileEx等。
      

  7.   

    unit copyflie;interface
    uses SysUtils,classes;procedure CopyFile(FromFileName,ToFileName:string);
    procedure copyFileFromPath(Frompath,ToPath:string);
    function IsValidDir(SearchRec:TSearchRec):integer;
    Function GetPath(s:string):string;
    implementation
    procedure CopyFile(FromFileName,ToFileName:string);
    var f1,f2: tfilestream ;
    begin
    f1:=Tfilestream.Create(Fromfilename,fmopenread);
    try
    f2:=Tfilestream.Create(Tofilename,fmopenwrite or fmcreate);
    try
    f2.CopyFrom(f1,f1.size);
    finally
    f2.Free;
    end;
    finally
    f1.Free;
    end;
    end;
    procedure copyFileFromPath(Frompath,ToPath:string);
    var searchRec:TsearchRec;
    begin
    try
    mkdir(Topath);
    except
    end;
     if (FindFirst(FromPath+'*.*', faDirectory, SearchRec)=0) then
     begin
       while (FindNext(SearchRec) = 0) do
            begin
             if  IsValidDir(SearchRec)=1 then
                 begin
                 copyFile(FromPath+SearchRec.Name,topath+SearchRec.Name);
                 end;
            end;
     end;
    end;
    function IsValidDir(SearchRec:TSearchRec):integer;
    begin
    if (SearchRec.Attr=16) and
    (SearchRec.Name<>'.') and
    (SearchRec.Name<>'..') then
    Result:=0
    else
    if (searchrec.Name <>'.') and
       (SearchRec.Attr<>17) and
       (searchrec.Name <>'..') then
    result:=1
    else
    Result:=-1;
    end;
    Function GetPath(s:string):string;
    var  le:integer;
    begin
    le:=length(s);
    if copy(s,le,1)<>'\'then
    s:=s+'\';
    result:=s;
    end;
    end.
    调用如下
    copyFileFromPath(getpath('c:\me\you'),getPath('d:\me\you'));
    不太精练,对用吧!