delphi获取目录下所有文件名[delphi]

procedure  searchfile(path:string);//细致,path背面要有'\';   
   var   
       SearchRec:TSearchRec;   
       found:integer;   
   begin   
       found:=FindFirst(path+'*.*',faAnyFile,SearchRec);   
       while    found=0    do   
         begin   
             if (SearchRec.Name<>'.')  and (SearchRec.Name<>'..')     
                   and    (SearchRec.Attr<>faDirectory)    then   
                 ListBox1.Add(SearchRec.Name);   
             found:=FindNext(SearchRec);   
         end;   
       FindClose(SearchRec);   
   end;  

//===============================================================

上面一个只获取当前目录下全部文件,要是要获取该目录下的子目录的文件,看下面   ,100脚本
   procedure  SearchFile(path:string);   
   var   
       SearchRec:TSearchRec;   
       found:integer;   
   begin   
       found:=FindFirst(path+'*.*',faAanyFile,SearchRec);   
       while    found=0    do   
         begin   
           if  (SearchRec.Name<>'.')  and  (SearchRec.name<>'..)  and   
                 (SearchRec.Name=faDirectory)    then   
               SearchFile(SearchRec.Name+'\')   
           else   
               LisBox1.Add(SearchRec.Name);   
           found:=FindNext(SearchREc);   
       end;   
       FindClose(SearchRec);   
   end;   
//===================================================================


你可能感兴趣的:(delphi获取目录下所有文件名[delphi])