在delphi程序中,如何获取一个文件的字节大小是多少? ( 积分: 10 )

  • 主题发起人 主题发起人 rzxiaojun
  • 开始时间 开始时间
R

rzxiaojun

Unregistered / Unconfirmed
GUEST, unregistred user!
用tsearchrec;<br>findfirst(...)<br>ok?
 
&nbsp;m_clFileStream: &nbsp; &nbsp; TFileStream;<br> m_clFileStream := TFileStream.Create(strFileName,fmOpenRead or &nbsp;fmShareDenyWrite);<br> m_iFileSize &nbsp; &nbsp;:= m_clFileStream.Size; &nbsp;{文件长度}<br> FreeAndNil(m_clFileStream);<br>
 
//lpFn: 文件名;<br>//能获得包括大于 4G 的文件大小.<br>function GetFileBytes(lpFn: PChar): Int64;<br>var<br> &nbsp;hFile, dwSizeLow, dwSizeHigh: Longword;<br>begin<br> &nbsp;Result := -1;<br> &nbsp;hFile := CreateFile(lpFn, GENERIC_READ, FILE_SHARE_READ, nil, OPEN_ALWAYS,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_ATTRIBUTE_NORMAL, 0);<br> &nbsp;try<br> &nbsp; &nbsp;if hFile &amp;lt;&amp;gt; INVALID_HANDLE_VALUE then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;dwSizeLow := GetFileSize(hFile, @dwSizeHigh);<br> &nbsp; &nbsp; &nbsp;Result := dwSizeHigh*4294967296 + dwSizeLow;<br> &nbsp; &nbsp;end;<br> &nbsp;finally<br> &nbsp; &nbsp;CloseHandle(hFile);<br> &nbsp;end;<br>end;
 
多人接受答案了。
 
后退
顶部