【发布时间】:2012-02-03 00:56:09
【问题描述】:
我有这个规则来了解文件大小:
(基于http://delphi.about.com/od/delphitips2008/qt/filesize.htm)
function FileSize(fileName : String) : Int64;
var
sr : TSearchRec;
begin
if FindFirst(fileName, faAnyFile, sr ) = 0 then
{$IFDEF MSWINDOWS}
result := Int64(sr.FindData.nFileSizeHigh) shl Int64(32) + Int64(sr.FindData.nFileSizeLow)
{$ELSE}
result := sr.Size
{$ENDIF}
else
result := -1;
FindClose(sr) ;
end;
但是,这给出了这个警告:
[DCC Warning] Funciones.pas(61): W1002 Symbol 'FindData' is specific to a platform
我想知道是否存在一种干净的跨平台方式来做到这一点。我检查了 TFile 类并没有找到它...
【问题讨论】:
-
令我沮丧的是 FindFirst 似乎是获取文件大小信息的方式。这是反直觉的,甚至并不总是准确的。
标签: delphi cross-platform compiler-warnings filesize