Ich nehme folgende Version:
(ist schneller: öffnet kein File, Ergebnis auch für grosse Files geeignet: INT64)
Delphi-Quellcode:
function GetFileSizeEx(const AFileName: string): Int64;
var F: TSearchRec;
begin
Result := -1;
if FindFirst(AFileName, faAnyFile, F) = 0 then
begin
try Result := F.FindData.nFileSizeLow or (F.FindData.nFileSizeHigh shl 32);
finally SYSTEM.SysUtils.FindClose(F); end;
end;
end;
//Alternative
function GetFileSize(const AFileName: string): Int64;
var
SearchRec: TSearchRec;
OldMode: Cardinal;
Size: TULargeInteger;
begin
Result := -1;
OldMode := SetErrorMode(SEM_FAILCRITICALERRORS);
try
if FindFirst(AFileName, faAnyFile, SearchRec) = 0 then
begin
Size.LowPart := SearchRec.FindData.nFileSizeLow;
Size.HighPart := SearchRec.FindData.nFileSizeHigh;
Result := Size.QuadPart;
SYSTEM.SysUtils.FindClose(SearchRec);
end;
finally
SetErrorMode(OldMode);
end;
end;