我想把一个文件夹的内容全部备份COPY到另个一个目录里面,怎么做啊?

解决方案 »

  1.   

    copyfile("源目录“,”目标目录“,flase)
      

  2.   

    //==============================================================================
    //拷贝目录(包括子目录一起拷贝)************************************************
    //==============================================================================
    procedure XCopyDir(SourceDir, TargetDir: string);
    var DirInfo: TSearchRec;
        DosError: Integer;
    begin
      DosError := FindFirst(SourceDir+'\*.*', FaAnyfile, DirInfo);
      if not DirectoryExists(TargetDir) then ForceDirectories(TargetDir);
      while DosError=0 do
      begin
        if ((DirInfo.Attr and FaDirectory)=faDirectory) and (DirInfo.Name<>'.') and (DirInfo.Name<>'..')
        then XCopyDir(SourceDir + '\' + DirInfo.Name, TargetDir + '\' + DirInfo.Name);
        {$IF DEFINED(WIN32) AND DECLARED(UsingVCL)}
        if ((DirInfo.Attr and FaDirectory)<>FaDirectory) and ((DirInfo.Attr and FaVolumeID)<>FaVolumeID)
        {$ELSE}
        if ((DirInfo.Attr and FaDirectory)<>FaDirectory)
        {$IFEND}
        then CopyFile(PChar(SourceDir + '\' + DirInfo.Name), PChar(TargetDir + '\' + DirInfo.Name), false);
        DosError := FindNext(DirInfo);
      end;
      SysUtils.FindClose(DirInfo);
    end;
      

  3.   

    uses ShellAPI;
    function CopyDirectory(const Source, Dest: string): boolean;
    var
      fo: TSHFILEOPSTRUCT;
    begin
      FillChar(fo, SizeOf(fo), 0);
      with fo do
      begin
        Wnd := 0;
        wFunc := FO_COPY;
        pFrom := PChar(source+#0);
        pTo := PChar(Dest+#0);
        fFlags := FOF_NOCONFIRMMKDIR;
      end;
      Result := (SHFileOperation(fo) = 0);
    end;