怎么样判断一个目录下有没有文件,谁能帮助写个函数。(50分)

  • 主题发起人 netwinds
  • 开始时间
N

netwinds

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么样判断一个目录下有没有文件,谁能帮助写个函数。只要判断有或没有就可,返回<br>TRUE与FALSE。
 
怎么没人来回答我啊?????
 
findfirst(文件名字符串,文件类型,tsearchrec变量)
 
试一下,我也不是很清楚 应该差不多<br>Fuction isDirectoryNull(Dir : String) : Boolean ;<br>var<br>&nbsp; tmpString : String ;<br>begin<br>&nbsp;tmpString := Dir ; &nbsp; <br>&nbsp;if tmpString[Length(tmpString)-1]&lt;&gt;'/' then<br>&nbsp; &nbsp; tmpString := tmpString+'/*.*' <br>&nbsp;else<br>&nbsp; &nbsp; tmpString := tmpString+'*.*' ;<br>&nbsp;result := FileExists(tmpString) ;<br>end;<br><br>
 
这样子更好,谢谢两位!!<br><br><br>Function isDirectoryNull(Dir : String) : Boolean ;<br>var<br>&nbsp; tmpString : String ;<br>&nbsp; sr: TSearchRec;<br>&nbsp; FileAttrs: Integer;<br>&nbsp; bolHaveFile:Boolean;<br>begin<br>&nbsp; tmpString := Dir ;<br>&nbsp; if tmpString[Length(tmpString)]&lt;&gt;'/' then begin<br>&nbsp; &nbsp; tmpString := tmpString+'/*.*';<br>&nbsp; end<br>&nbsp; else begin<br>&nbsp; &nbsp; tmpString := tmpString+'*.*' ;<br>&nbsp; end;<br>&nbsp; FileAttrs :=faReadOnly+faHidden+faSysFile+faVolumeID+faDirectory+faArchive+faAnyFile;<br>&nbsp; if FindFirst(tmpString, FileAttrs, sr) = 0 then begin<br>&nbsp; &nbsp; repeat<br>&nbsp; &nbsp; &nbsp; if (sr.Name &lt;&gt;'.') and (sr.Name &lt;&gt;'..') then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; bolHaveFile:=True;<br>&nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; else begin<br>&nbsp; &nbsp; &nbsp; &nbsp; bolHaveFile:=False;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; until FindNext(sr) &lt;&gt; 0;<br>&nbsp; &nbsp; FindClose(sr);<br>&nbsp; end;<br>&nbsp; Result:=not bolHaveFile;<br>end;<br>
 
顶部