VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

GetDiskFreeSpaceEx

Konstantin Vasserman  (1 Submission)   Windows API Call/Explanation   Visual Basic 3.0   Intermediate   Wed 3rd February 2021

This code shows how to use GetFreeDiskSpaceEx API. It works with the drives larger than 2GB as oppose to the old GetFreeDiskSpace API call. It will also work with Windows2000 per-user space quota, so the free disk space you get is actually what available to the user and not all the space available on the disk.

Inputs
Pass any valid path to the GetFreeSpace function. The path could be a local drive ("c:" or "c:\windows"), network drive ("x:" or "x:\MyFolder") or UNC path like "\\myserver\myshare".

Assumes
Under Windows 2000: if per-user quotas are in use, the value returned by GetFreeSpace function may be less than the total number of free bytes on the disk. This code can be modified to get total number of free bytes on the disk (without regard to the user quota) or total number of bytes on the disk.

Returns
GetFreeSpace function returns total number of free bytes on the disk that are available to the user associated with the calling thread. Return value is a Double.

Side Effects
This code will not work on versions of Windows 95 prior to OSR2.

API Declarations
Public Type ULong ' Unsigned Long
Byte1 As Byte
Byte2 As Byte
Byte3 As Byte
Byte4 As Byte
End Type
Public Type LargeInt ' Large Integer
LoDWord As ULong
HiDWord As ULong
LoDWord2 As ULong
HiDWord2 As ULong
End Type
Public Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" _
(ByVal lpRootPathName As String, FreeBytesAvailableToCaller As LargeInt, _
TotalNumberOfBytes As LargeInt, TotalNumberOfFreeBytes As LargeInt) As Long

Rate GetDiskFreeSpaceEx (3(3 Vote))
GetDiskFreeSpaceEx.bas

GetDiskFreeSpaceEx Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters