Article ID: 139548
Article Last Modified on 7/30/1999
**---------------------------------------------------------------**
** Program: Getspace.prg **
** Purpose: Demonstrates how to declare and call the Win32 **
** GetDiskFreeSpace API. **
**---------------------------------------------------------------**
PUBLIC lpRootPathName, ;
lpSectsPerCluster, ;
lpBytesPerSector, ;
lpNumberOfFreeClusters, ;
lpTotalNumberOfClusters
lpRootPathName = "A:\"
lpSectsPerCluster = 0
lpBytesPerSect = 0
lpNumOfFreeClusters = 0
lpTotNumOfClusters = 0
DECLARE INTEGER GetDiskFreeSpace IN Win32API AS GetDiskSpace ;
STRING @lpRootPathName, ;
INTEGER @lpSectsPerCluster, ;
INTEGER @lpBytesPerSect, ;
INTEGER @lpNumOfFreeClusters, ;
INTEGER @lpTotNumOfClusters
RetVal=GetDiskSpace(@lpRootPathName, @lpSectsPerCluster, @lpBytesPerSect, ;
@lpNumOfFreeClusters, @lpTotNumOfClusters)
DEFINE WINDOW ShowInfo FROM 0,0 TO 12,70 ;
FLOAT CLOSE ;
TITLES "Drive Information for " + ;
ALLTRIM(lpRootPathName) ;
FONT "Courier",10
ACTIVATE WINDOW ShowInfo
MOVE WINDOW ShowInfo CENTER
@ 0,1 SAY "Drive & path name : " + ;
ALLTRIM(lpRootPathName)
@ 1,1 SAY "Sectors per cluster : " + ;
ALLTRIM(STR(lpSectsPerCluster))
@ 2,1 SAY "Bytes per Sector : " + ;
ALLTRIM(STR(lpBytesPerSect))
@ 3,1 SAY "Number of free clusters : " + ;
ALLTRIM(STR(lpNumOfFreeClusters))
@ 4,1 SAY "Total number of clusters : " + ;
ALLTRIM(STR(lpTotNumOfClusters))
@ 5,1 SAY "==================================================="
@ 6,1 SAY "Total disk space : " + ;
ALLTRIM(STR(lpSectsPerCluster * lpBytesPerSect * lpTotNumOfClusters))
@ 7,1 SAY "Free disk space : " + ;
ALLTRIM(STR(lpSectsPerCluster * lpBytesPerSect * lpNumOfFreeClusters))
@ 8,1 SAY "Used disk space : " + ;
ALLTRIM(STR(lpSectsPerCluster * lpBytesPerSect * ;
(lpTotNumOfClusters - lpNumOfFreeClusters)))
**--------------------------<End Code>---------------------------**
When this code is run on a 1.44-megabyte floppy disk, the following output
is what you would get if the floppy disk is a new, formatted floppy disk
that contains no data:
Drive & path name : A:\ Sectors per cluster : 1 Bytes per sector : 512 Number of free clusters : 2847 Total number of clusters : 2847 =================================== Total disk space : 1457664 Free disk space : 1457664 Used disk space : 0Using this API call, you can quickly and easily determine how much disk space you have available for your program. A related disk API (GetVolumeInformation) provides information about the disk physical characteristics such as the file system and file compression.
139172 PRB: Visual FoxPro CD-ROM Compact Disc Includes Extra Files
Additional query words: VFoxWin drive volume space free attributes
Keywords: kbcode KB139548