DelphiBasics
DiskSize
Function
Gives the size in bytes of a specified drive SysUtils unit
 function DiskSize(Drive Byte):Int64;
Description
The DiskSize function gives the size in bytes of the given Drive.
 
If the drive is invalid, or no media, -1 is returned
 
If the drive is read-only, 0 is returned.
 
The Drive is designated as follows:
 
= A drive
= B drive
= C drive
... 
Related commands
DiskFreeGives the number of free bytes on a specified drive
 Download this web site as a Windows program.




 
Example code : Show the size in bytes of drives B to F on your PC
var
  i     : Integer;
  space : Int64;

begin
  // Display the free space on drives B, C, D, E, F, where present
  for i := 2 to 6 do
  begin
    space := DiskSize(i);

    if space >= 0
    then ShowMessage(Chr(i+64)+' Drive size = '+
                     FloatToStrF(space, ffNumber, 20, 0))
    else ShowMessage(Chr(i+64)+' Drive not present');
  end;
end;
Show full unit code
  Example output is as follows:
  
  B Drive not present
  C Drive size = 11,997,143,040
  D Drive size = 7,995,756,544
  E Drive size = 686,587,904
  F Drive size = 591,429,632
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page