Kbase 17119: How to Call WIN32 API Function: GetDiskFreeSpace
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
How to Call WIN32 API Function: GetDiskFreeSpace
DISCLAIMER:
===========
The code example in this knowledgebase is for informational purposes
only. If you have specific questions about which API calls would be
best suited to your design goals, please consult your Microsoft
documentation.
INTRODUCTION:
=============
The following sample code shows how to call the Win32 API function
called GetDiskFreeSpace. This function returns the format information
about a disk along with the number of free clusters.
This code has been tested on Windows NT 4.0 Workstation only.
The following shows what the information returned from the function
call means:
intSectorsPerCluster = The number of sectors per cluster. A sector
is a contiguous group of bytes stored on disk.
A cluster is a block of sectors.
intBytesPerSector = The number of bytes per sector. To determine
the number of bytes per cluster, simply
multiply the value returned in intSectorsPer-
Cluster by the value in intBytesPerSector.
intFreeClusters = The number of free clusters. Multiply this
times the number of sectors per cluster and
the number of bytes per sector to determine
the free space remaining on the disk. Please
remember that turning on data compression will
skew these values significantly.
intClusters = The total number of clusters on the drive.
DEFINE VARIABLE intSectorsPerCluster AS INTEGER NO-UNDO.
DEFINE VARIABLE intBytesPerSector AS INTEGER NO-UNDO.
DEFINE VARIABLE intFreeClusters AS INTEGER NO-UNDO.
DEFINE VARIABLE intClusters AS INTEGER NO-UNDO.
DEFINE VARIABLE intBytesFree AS INTEGER NO-UNDO.
DEFINE VARIABLE intResult AS INTEGER NO-UNDO.
PROCEDURE GetDiskFreeSpaceA EXTERNAL "KERNEL32.DLL":
DEFINE INPUT PARAMETER chrRootPathName AS CHARACTER.
DEFINE OUTPUT PARAMETER intSectorsPerCluster AS LONG.
DEFINE OUTPUT PARAMETER intBytesPerSector AS LONG.
DEFINE OUTPUT PARAMETER intFreeClusters AS LONG.
DEFINE OUTPUT PARAMETER intClusters AS LONG.
DEFINE RETURN PARAMETER intResult AS SHORT.
END PROCEDURE.
RUN GetDiskFreeSpaceA (INPUT "C:\",
OUTPUT intSectorsPerCluster,
OUTPUT intBytesPerSector,
OUTPUT intFreeClusters,
OUTPUT intClusters,
OUTPUT intResult).
IF intResult = 1 THEN
DO:
ASSIGN intBytesFree = intFreeClusters *
intSectorsPerCluster *
intBytesPerSector.
MESSAGE STRING(intBytesFree,">>>,>>>,>>>,>>9") +
"Bytes Free on C:\" VIEW-AS ALERT-BOX.
END.
ELSE
MESSAGE "Function Failed. Drive Most Likely Doesn't Exist"
VIEW-AS ALERT-BOX.
Progress Software Technical Support Note # 17119