Link to home
Start Free TrialLog in
Avatar of mi6agent
mi6agent

asked on

Get size of file

before anyone gives me examples read on first.......


Does anyone have examples on how to use the Windows API to get the size of a file in bytes - must be able to handle HUGE files (ie: any size of file on a Windows system 4Gb upwards).

I want to use Windows API as i am assuming it is faster than going through the delphi way.
Avatar of geobul
geobul

Hi,

Try this:

function GetFileSize(const strFile: string): Int64;
var
  SearchRec:TSearchRec;
begin
  result := 0;
  if (FindFirst(strFile, faAnyFile, SearchRec)=0) then begin
    // File found.
    result := (Int64(SearchRec.FindData.nFileSizeHigh) shl 32) + SearchRec.FindData.nFileSizeLow;
  end;
  FindClose(SearchRec);
end;

usage:
ShowMessage(IntToStr(GetFileSize(Edit1.Text)));

Regards, Geo
ASKER CERTIFIED SOLUTION
Avatar of DragonSlayer
DragonSlayer
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
LoL, sorry, didn't see Geo's comment... didn't press Refresh :-p
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mi6agent

ASKER

Thanks to both of you - i have raised the points and split them to give origianl 125 points each.

DragonSlayer - i used your code BUT changed OPEN_ALWAYS to OPEN_EXISTING - OPEN_ALWAYS will create the file if it is not found.