求在treeview中遍历特定文件夹下的文件夹和文件的递归函数?急!多谢!

解决方案 »

  1.   

    在treeview 中历遍文件夹?没听说过呢
    历遍指定目录下的文件夹和文件倒是可以
      

  2.   


    function FindFile(sDirectory, ExtName: string): string; //目录名,扩展名
       var sr:TSearchRec;
           sPath,sFile,Temp:string;
    begin
      if Copy(sDirectory,length(sDirectory),1)<>'\' then    //子目录
        sPath:=sDirectory+'\'
      else
        sPath:=sDirectory;
      if FindFirst(sPath+'*.*',faAnyFile,sr)=0 then
      begin
        Repeat
          sFile:=sr.Name;
          if (sFile='.') or (sFile='..') then continue;
          sFile:=sPath+sr.Name;                     //递归调用时,路径一定要正确
          if ((sr.Attr and faDirectory)  <>0 ) then //目录
          begin
            FindFile(sFile,ExtName);  //文件夹
         end                                       //文件
          else if ((sr.Attr and faAnyFile) = sr.Attr) then
          begin
            Temp := ExtractFileExt(sFile);
            Temp := Copy(Temp,Pos('.',Temp) + 1,Length(Temp) - 1 );
            if UpperCase(Temp) = UpperCase(ExtName) then
              lst1.Items.Add(sFile);
          end;
        until FindNext(sr)<>0 ;
        FindClose(sr);
      end;
    end;