求一个目录中文件数量统计的函数(100分)

  • 主题发起人 主题发起人 葡萄
  • 开始时间 开始时间

葡萄

Unregistered / Unconfirmed
GUEST, unregistred user!
我想统计一个目录中所有文件的数量,包含子目录中文件的数量,不知道用什么函数,希望高手能指点一下~
 
function FileNum(const Path: string): Integer;<br>var<br>&nbsp; f: TSearchRec;<br>&nbsp; Ret: Integer;<br>begin<br>&nbsp; Result:=0;<br>&nbsp; Ret:=FindFirst(Path+'/*.*', faAnyFile, f);<br>&nbsp; while Ret=0 do<br>&nbsp; begin<br>&nbsp; &nbsp; if (f.Name&lt;&gt;'.') and (f.Name&lt;&gt;'..') then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Inc(Result);<br>&nbsp; &nbsp; &nbsp; if (f.Attr and faDirectory)&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; Result:=Result+FileNum(Path+'/'+f.Name)<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; FindNext(f)<br>&nbsp; end<br>end;
 
http://www.cbifamily.com/showcontent.php?articleid=7239
 
二楼的朋友你的函数为什么是个死循环啊~~
 
function FileNum(const Path: string): Integer;<br>var<br>&nbsp;f: TSearchRec;<br>&nbsp;Ret: Integer;<br>begin<br>&nbsp;Result:=0;<br>&nbsp;Ret:=FindFirst(Path+'/*.*', faAnyFile, f);<br>&nbsp;while Ret=0 do<br>&nbsp;begin<br>&nbsp; &nbsp;if (f.Name&lt;&gt;'.') and (f.Name&lt;&gt;'..') then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;Inc(Result);<br>&nbsp; &nbsp; &nbsp;if (f.Attr and faDirectory)&gt;0 then<br>&nbsp; &nbsp; &nbsp; &nbsp;Result:=Result+FileNum(Path+'/'+f.Name)<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;Ret:=FindNext(f)<br>&nbsp;end<br>end; &nbsp;<br>
 
楼上的朋友谢谢,分是你的了
 
后退
顶部