想复制一个文件,此文件下有多个目录,但不想复制隐藏的文件用什么方法?我的代码如下: 怎样改??
   //拷贝所有目录文件 
Function MyUtil_CopyDirectory(SourceDir, TargetDir:pchar; Recursive:integer):integer;stdcall;
var
   r:TSearchRec;
   li_return : integer;
   errorMessage: string;
begin
errorMessage := '';
if not DirectoryExists(TargetDir) then CreateDir(TargetDir);
try
   if FindFirst(SourceDir+'*.*', faDirectory+faArchive, r)=0 then
      repeat
         if (r.Name<>'.') and (r.Name<>'..') then
            if (r.Attr and faDirectory<>0) and (Recursive = 1) then
               MyUtil_CopyDirectory(pchar(SourceDir+r.Name+'\'), pchar(TargetDir+r.Name+'\'), Recursive)
            else
               if r.Attr and faArchive<>0 then
                  //拷贝文件
                  CopyFile(PChar(SourceDir+r.Name), PChar(TargetDir+r.Name), False);
      until FindNext(r)<>0;
      li_return := 1;
   except
     on E: Exception do
        begin
           ErrorMessage := string(E.Message);
           li_return := -1;
        end;
   end;
   result := li_return;
end;

解决方案 »

  1.   

    if r.Attr and faHidden<>0 then
    do things you want.....pls have a try!
      

  2.   

    if (r.Attr and faHidden) = faHidden then 不複製
      

  3.   

    procedure XCopyDir(SourceDir, TargetDir: string);
    var DirInfo: TSearchRec;
        DosError: Integer;
    begin
      DosError := FindFirst(SourceDir+'\*.*', faDirectory, 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;
    //终于解决了