SysUtils.FindFirst 的问题 ( 积分: 50 )

  • 主题发起人 主题发起人 hlei
  • 开始时间 开始时间
H

hlei

Unregistered / Unconfirmed
GUEST, unregistred user!
function CompareFileSize(FileName1: String; FileName2: String): Integer;<br>var<br> &nbsp;SearchRec: TSearchRec;<br> &nbsp;File1Size: Longint;<br> &nbsp;File2Size: Longint;<br>begin<br> &nbsp;try<br> &nbsp; &nbsp;if FindFirst (ExpandFileName(FileName1),faAnyFile,SearchRec)=0<br> &nbsp; &nbsp;then<br> &nbsp; &nbsp; &nbsp; File1Size:= SearchRec.Size<br> &nbsp; &nbsp;else Result:= -1 &nbsp;//FileName1不存在,就返回 -1<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp; FindClose(SearchRec);<br> &nbsp; &nbsp;end;<br> &nbsp;try<br> &nbsp; &nbsp;if FindFirst (ExpandFileName(FileName2),faAnyFile,SearchRec)=0<br> &nbsp; &nbsp;then<br> &nbsp; &nbsp; &nbsp; File2Size:= SearchRec.Size<br> &nbsp; &nbsp;else Result:= -2 //FileName2不存在,就返回 -2<br> &nbsp; finally<br> &nbsp; &nbsp; &nbsp; FindClose(SearchRec);<br> &nbsp; end;<br><br> &nbsp;if File1size &gt; File2Size then<br> &nbsp;Result:= 1 else //FileName1 &gt; FileName2 返回 1<br> &nbsp;if File1Size &lt; File2Size then<br> &nbsp;Result:= 2 else //FileName1 &lt; FileName2 返回 2<br> &nbsp;Result:= 0 //FileName1 = FileName2 返回 0<br>end;<br><br>为什么 1 2 0 都可以正确返回,可是 -1 -2(就是文件不存在时)返回的还是1 2<br>请帮我看看。
 
function CompareFileSize(FileName1: String; FileName2: String): Integer;<br>var<br> &nbsp;SearchRec: TSearchRec;<br> &nbsp;File1Size: Longint;<br> &nbsp;File2Size: Longint;<br>begin<br> &nbsp;try<br> &nbsp; &nbsp;if FindFirst (ExpandFileName(FileName1),faAnyFile,SearchRec)=0<br> &nbsp; &nbsp;then<br> &nbsp; &nbsp; &nbsp; File1Size:= SearchRec.Size<br> &nbsp; &nbsp;else Result:= -1 &nbsp;//FileName1不存在,就返回 -1<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp; FindClose(SearchRec);<br> &nbsp; &nbsp;end;<br> &nbsp;try<br> &nbsp; &nbsp;if FindFirst (ExpandFileName(FileName2),faAnyFile,SearchRec)=0<br> &nbsp; &nbsp;then<br> &nbsp; &nbsp; &nbsp; File2Size:= SearchRec.Size<br> &nbsp; &nbsp;else Result:= -2 //FileName2不存在,就返回 -2<br> &nbsp; finally<br> &nbsp; &nbsp; &nbsp; FindClose(SearchRec);<br> &nbsp; end;<br><br> &nbsp;if File1size &gt; File2Size then<br> &nbsp;Result:= 1 else //FileName1 &gt; FileName2 返回 1<br> &nbsp;if File1Size &lt; File2Size then<br> &nbsp;Result:= 2 else //FileName1 &lt; FileName2 返回 2<br> &nbsp;Result:= 0 //FileName1 = FileName2 返回 0<br>end;<br><br>为什么 1 2 0 都可以正确返回,可是 -1 -2(就是文件不存在时)返回的还是1 2<br>请帮我看看。
 
呵呵,自己发现了...<br>谢谢,各位观众!<br>结贴.
 
鼓掌欢迎,终于靠自己解决问题了,可喜可贺,嘿
 
呵,-_-!!!
 
后退
顶部