GetDiskFreeSpaceEx()

Purpose
The GetDiskFreeSpaceEx function obtains information about the amount of space available on a disk volume: the total amount of space, the total amount of free space, and the total amount of free space available to the user associated with the calling thread.
 
Library Transcribed by Date of page Updated on
Kernel32.dll Bo Thomsen/J.Paris 22.04.06  
 
Restrictions on use
none
 
Declare 32-bit

Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll"

  Alias "GetDiskFreeSpaceExA"

    (ByVal lpDirectoryName As String,

    lpFreeBytesAvailableToCaller As ULARGE_INTEGER,

    lpTotalNumberOfBytes As ULARGE_INTEGER,

    lpTotalNumberOfFreeBytes As ULARGE_INTEGER)

  As integer

 
Required Type definition
ULARGE_INTEGER
 
Parameters

lpDirectoryName

 

 

 

 

 

lpFreeBytesAvailableToCaller

 

 

 

lpTotalNumberOfBytes

 

lpTotalNumberOfFreeBytes

Pointer to a null-terminated string that specifies a directory on the disk of interest. This string can be a UNC name. If lpDirectoryName is NULL, the GetDiskFreeSpaceEx function obtains information about the disk that contains the currect directory. Note that lpDirectoryName does not have to specify the root directory on a disk. The function accepts any directory on the disk.


Pointer to a variable to receive the total number of free bytes on the disk that are available to the user associated with the calling thread.
If the operating system implements per-user quotas, this value may be less than the total number of free bytes on the disk.

 

Pointer to a variable to receive the total number of bytes on the disk.

Pointer to a variable to receive the total number of free bytes on the disk. This parameter can be NULL

 
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
 
Example

Type ULARGE_INTEGER

  LowPart As integer

  HighPart As integer

End Type

 

Declare Function GetDiskFreeSpaceEx Lib "kernel32.dll"

  Alias "GetDiskFreeSpaceExA"

    (ByVal lpDirectoryName As String,

    lpFreeBytesAvailableToCaller As ULARGE_INTEGER,

    lpTotalNumberOfBytes As ULARGE_INTEGER,

    lpTotalNumberOfFreeBytes As ULARGE_INTEGER)

  As integer

 

declare sub main

declare function GetDiskFreeSpace (ByVal sDir as string) as float

 

sub main

  note "Free space on C-drive (Byte): " + GetDiskFreeSpace("c:\")

end sub

 

function GetDiskFreeSpace (ByVal sDir as string) as float

  dim t1, t2, t3 As ULARGE_INTEGER, fTmp as float

  if GetDiskFreeSpaceEx(sDir, t1, t2, t3) > 0 then

    fTmp = t3.Highpart * 2.0^32

    if t3.Lowpart < 0 then

'     Correction for MapBasic interpreting the most significant bit as a sign bit

      fTmp = fTmp + t3.Lowpart + 2.0^32

    else

      fTmp = fTmp + t3.Lowpart

    end if  

  else

    fTmp = -1.0

  end if

  GetDiskFreeSpace = fTmp

end function

 
Comments

Indirect call through a pure MB function necessary to handle large integers as float variables.

 
See also