BigOne
asked on
Simple Drivespace Question
What can I do to get the current available space on a specific drive? What are some pitfalls and tricks I should be aware of?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Opps, a little late.
Windows 95:
The GetDiskFreeSpace function returns incorrect values for volumes that are larger than 2 gigabytes. The function caps the values stored into *lpNumberOfFreeClusters and *lpTotalNumberOfClusters so as to never report volume sizes that are greater than 2 gigabytes.
Even on volumes that are smaller than 2 gigabytes, the values stored into *lpSectorsPerCluster, *lpNumberOfFreeClusters, and *lpTotalNumberOfClusters values may be incorrect. That is because the operating system manipulates the values so that computations with them yield the correct volume size.
Windows 95 OSR2 and Windows 98:
The GetDiskFreeSpaceEx function is available on beginning with Windows 95 OEM Service Release 2 (OSR2). The GetDiskFreeSpaceEx function returns correct values for all volumes, including those that are greater than 2 gigabytes.
To determine whether GetDiskFreeSpaceEx is available, call GetModuleHandle to get the handle to Kernel32.dll. Then you can call GetProcAddress.
The following code fragment shows one way to do this:
pGetDiskFreeSpaceEx = GetProcAddress( GetModuleHandle("kernel32. dll"),
"GetDiskFreeSpaceExA");
if (pGetDiskFreeSpaceEx)
{
fResult = pGetDiskFreeSpaceEx (pszDrive,
(PULARGE_INTEGER)&i64FreeB ytesToCall er,
(PULARGE_INTEGER)&i64Total Bytes,
(PULARGE_INTEGER)&i64FreeB ytes);
// Process GetDiskFreeSpaceEx results.
}
else
{
fResult = GetDiskFreeSpace (pszDrive,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters)
// Process GetDiskFreeSpace results.
}
It is not necessary to call LoadLibrary on Kernel32.dll because it is already loaded into every Win32 process's address space.
On Windows NT 4.0 or later, use GetDiskFreeSpaceEx.
The GetDiskFreeSpace function returns incorrect values for volumes that are larger than 2 gigabytes. The function caps the values stored into *lpNumberOfFreeClusters and *lpTotalNumberOfClusters so as to never report volume sizes that are greater than 2 gigabytes.
Even on volumes that are smaller than 2 gigabytes, the values stored into *lpSectorsPerCluster, *lpNumberOfFreeClusters, and *lpTotalNumberOfClusters values may be incorrect. That is because the operating system manipulates the values so that computations with them yield the correct volume size.
Windows 95 OSR2 and Windows 98:
The GetDiskFreeSpaceEx function is available on beginning with Windows 95 OEM Service Release 2 (OSR2). The GetDiskFreeSpaceEx function returns correct values for all volumes, including those that are greater than 2 gigabytes.
To determine whether GetDiskFreeSpaceEx is available, call GetModuleHandle to get the handle to Kernel32.dll. Then you can call GetProcAddress.
The following code fragment shows one way to do this:
pGetDiskFreeSpaceEx = GetProcAddress( GetModuleHandle("kernel32.
"GetDiskFreeSpaceExA");
if (pGetDiskFreeSpaceEx)
{
fResult = pGetDiskFreeSpaceEx (pszDrive,
(PULARGE_INTEGER)&i64FreeB
(PULARGE_INTEGER)&i64Total
(PULARGE_INTEGER)&i64FreeB
// Process GetDiskFreeSpaceEx results.
}
else
{
fResult = GetDiskFreeSpace (pszDrive,
&dwSectPerClust,
&dwBytesPerSect,
&dwFreeClusters,
&dwTotalClusters)
// Process GetDiskFreeSpace results.
}
It is not necessary to call LoadLibrary on Kernel32.dll because it is already loaded into every Win32 process's address space.
On Windows NT 4.0 or later, use GetDiskFreeSpaceEx.
ASKER
Thanks for your help, sorry about the OS, it is NT4.0, my bad. Good answer.
What OS are you using?