Function DiskSpace() Foundation
Determines the storage space available on a drive.
DiskSpace( [<cDrive>] ) --> nBytes
DiskSpace() returns an integer numeric value indicating the available storage space on the specified drive in bytes. If the operating system cannot access the specified drive, a runtime error is generated.
Under an early Windows 95 version (prior to the OSR 2 release) the return value may be incorrect for disk partitions of more than 2 gigabytes.
The environment function DiskSpace() determines the free storage capacity on a disk drive. It is often used with routines that copy data from a hard disk to a diskette. The size of the files to be copied can be determined with the function Directory() or the low level file functions FOpen() and FSeek(). When DBF files are to be copied, their size can also be determined using the functions RecSize() and LastRec().
DiskSpace() does not use the drive setting specified with SET DEFAULT.
// In the example, a data storage routine uses Fseek() to
// determine the number of bytes to be saved. The
// function DiskSpace() returns the free storage space.
// Symbolic constants from the Header file Fileio.ch
// are used.
#include "Fileio.ch"
PROCEDURE Main
? BackUp( "A:" , {"CUSTOMER.DBF","CUSTOMER.DBT"} )
RETURN
FUNCTION BackUp( cDrive, aFiles )
LOCAL lSuccess := .F.
LOCAL nTotalBytes := 0
LOCAL nHandle, n, nLen
nLen := Len( aFiles )
FOR n:= 1 TO nLen // sum data sizes
IF ( nHandle := FOpen( aFiles[n] ) ) > 0
nTotalBytes += FSeek( nHandle, 0, FS_END )
FClose( nHandle )
ENDIF
NEXT
IF nTotalBytes < DiskSpace( cDrive )
FOR n:= 1 TO nLen // copy files
COPY FILE ( aFiles[n] ) TO ( cDrive + "\" + aFiles[n] )
NEXT
lSuccess := .T.
ENDIF
RETURN lSuccess
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.