Friday, 9 May 2008

Get the size of a file (more than 2 GB) With this function you can receive the size of a file, it still works correctly with sizes larger than 2 GB.

Get the size of a file (more than 2 GB)

With this function you can receive the size of a file, it still works correctly with sizes larger than 2 GB.

uses SysUtils;

////////////////////////////////////////////////////////////////
// this function determines the size of a file in bytes, the size
// can be more than 2 GB.
function Sto_GetFileSize(const FileName: String): Int64;
var
myFile: THandle;
myFindData: TWin32FindData;
begin
// set default value
Result := 0;
// get the file handle.
myFile := FindFirstFile(PChar(FileName), myFindData);
if (myFile <> INVALID_HANDLE_VALUE) then
begin
Windows.FindClose(myFile);
Int64Rec(Result).Lo := myFindData.nFileSizeLow;
Int64Rec(Result).Hi := myFindData.nFileSizeHigh;
end;
end;

Reference: http://www.martinstoeckli.ch

0 comments: