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 //SearchRec.Attr=faDirectory 等于文件夹
    showmessage(SearchRec.Name);
  Found:=FindNext(SearchRec);
  end;
  FindClose(SearchRec);
end;

上面一个只获取当前目录下所有文件夹,下面的还没有修改

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;

  

posted on 2017-03-22 11:28  酷瑞  阅读(1212)  评论(0编辑  收藏  举报

导航