Function DiskSpace() Foundation

Determines the storage space available on a drive.

Syntax
DiskSpace( [<cDrive>] ) --> nBytes
Parameters
<cDrive>
<cDrive> is a character expression specifying a drive. It can be specified in the form "A" or "C:". When <cDrive> is missing or has an invalid data type, the storage space of the current drive is determined.
Return

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.

Description

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.

For compatibility reasons, a numeric value can be indicated for <cDrive>. When <cDrive> is a numeric value, 1 designates drive "A", 2 stands for drive "B", 3 for drive "C" etc.

Examples
DiskSpace()
// 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 

Feedback

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.