问:如何遍例一个文件夹下的所有子文件夹

解决方案 »

  1.   

    function searchfile(path,SearchName : String):string; //文件查找
    var
        SR            : TSearchRec;
        dirlist:Tstringlist;
        tmp:string;
        dt:tdatetime;
    begin
      dirlist:=Tstringlist.Create;
      if path[length(path)]<>'\' then  path:=path+'\';
      If FindFirst(path+searchname,faAnyFile,SR)=0then
        Repeat
           dirlist.Clear;
          If (SR.Attr<>faDirectory) and (SR.Name[1]<>'.') then
              begin
                tmp:=path+sr.Name;
                dirlist.Add(tmp);
                tmp:=Format('%1.0n', [sr.Size+0.0]);
                dirlist.Add(tmp);
                dt := FileDateToDateTime(sr.Time);
                tmp:=FormatDateTime('yyyy-mm-dd  hh:nn ampm', dt);
                dirlist.Add(tmp);
                filelist.Add(dirlist.CommaText);
              end;
        Until (FindNext(SR)<>0);
      FindClose(SR);
      If FindFirst(path+'*.*',faAnyFile,SR)=0 then
        begin
          Repeat
            if (sr.Name='.')or(sr.Name='..') then continue;
            if (sr.Attr=faDirectory) then
              searchfile(path+SR.Name+'\',SearchName);
          Until (FindNext(SR)<>0);
        end;
      FindClose(SR);
      Result := filelist.Text;
       DirList.Free;
    end;
      

  2.   

    procedure findall(disk,path: String; var fileresult: Tstrings); 
    varfpath: String;fs: TsearchRec;beginfpath:=disk+path+'\*.*';if findfirst(fpath,faAnyFile,fs)=0 thenbeginif (fs.Name<>'.')and(fs.Name<>'..') thenif (fs.Attr and faDirectory)=faDirectory thenfindall(disk,path+'\'+fs.Name,fileresult)elsefileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');while findnext(fs)=0 dobeginif (fs.Name<>'.')and(fs.Name<>'..') thenif (fs.Attr and faDirectory)=faDirectory thenfindall(disk,path+'\'+fs.Name,fileresult)elsefileresult.add(disk+strpas(strupper(pchar(path)))+'\'+strpas(strupper(pchar(fs.Name)))+'('+inttostr(fs.Size)+')');end;end;findclose(fs);end;