function FindAllFile(DPath:string;FindType:integer):integer;//目录名字和文件列表还是目录列表 var Found:integer; SearchRec:TSearchRec; //,Attr DirList,FileList:TStrings; //目录名列表和文件名列表 Procedure ProcessSearchRec(SRec:TSearchRec); begin if (SRec.Name<>'.') and (SRec.Name<>'..') and (SRec.Attr=16) then DirList.Add(SRec.Name); if (SRec.Name<>'.') and (SRec.Name<>'..') and (SRec.Attr<>16) then //Action.ini列表 FileList.Add(SRec.Name); end; begin DirList:=TStringList.Create; FileList:=TStringList.Create; Found := FindFirst(DPath+'\*.*', faAnyFile, SearchRec); while Found = 0 do begin ProcessSearchRec(SearchRec); Found := FindNext(SearchRec); end; FindClose(SearchRec); if FindType=0 then Result:=DirList.Count; if FindType=1 then Result:=FileList.Count; DirList.Free; FileList.Free; end;以前自己用的函数,调用方式 count:=FindAllFile('D:\MASTERJAMES\MM',0);
D:\MASTERJAMES\MM\GF2
D:\MASTERJAMES\MM\GF3
D:\MASTERJAMES\MM\则为3
var
Found:integer; SearchRec:TSearchRec; //,Attr
DirList,FileList:TStrings; //目录名列表和文件名列表
Procedure ProcessSearchRec(SRec:TSearchRec);
begin
if (SRec.Name<>'.') and (SRec.Name<>'..') and (SRec.Attr=16) then
DirList.Add(SRec.Name);
if (SRec.Name<>'.') and (SRec.Name<>'..') and (SRec.Attr<>16) then //Action.ini列表
FileList.Add(SRec.Name);
end;
begin
DirList:=TStringList.Create;
FileList:=TStringList.Create; Found := FindFirst(DPath+'\*.*', faAnyFile, SearchRec);
while Found = 0 do
begin
ProcessSearchRec(SearchRec);
Found := FindNext(SearchRec);
end;
FindClose(SearchRec);
if FindType=0 then
Result:=DirList.Count;
if FindType=1 then
Result:=FileList.Count;
DirList.Free;
FileList.Free;
end;以前自己用的函数,调用方式 count:=FindAllFile('D:\MASTERJAMES\MM',0);
FindNext;
FindClose;