使用copyfile函数
函数原形如下Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" (ByVal lpExistingFileName As String, ByVal lpNewFileName As String, ByVal bFailIfExists As Long) As Long

解决方案 »

  1.   

    谢谢两位!!
    有人告诉我使用结构tshfileopstruct,该怎么用?继续请教!!
      

  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;