方法1:

function GetFileSize(const strFileName: string): Int64;
var
Handle: THandle;
FindData: TWin32FindData;
nFileSize: Int64;
begin
Result := -1;
Handle := FindFirstFile(PChar(strFileName), FindData);
if Handle <> INVALID_HANDLE_VALUE then
begin
Windows.FindClose(Handle);
if (FindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) = 0 then
begin
Int64Rec(nFileSize).Lo := FindData.nFileSizeLow;
Int64Rec(nFileSize).Hi := FindData.nFileSizeHigh;
Result := nFileSize;
end;
end;
end;方法2:
function GetFileSize(const strFileName: string): Int64;
var
sr: TSearchRec;
begin
if not FileExists(strFileName) then
begin
Result := -1;
Exit;
end;
if FindFirst(strFileName, faAnyFile, sr) = 0 then
Result := Int64(sr.FindData.nFileSizeHigh) shl 32 + Int64(sr.FindData.nFileSizeLow)
else
Result := -1;
FindClose(sr);
end;