Click or drag to resize

DiskFree Function (String)

X#
Return the space available on a specified disk.

Namespace:  XSharp.Core
Assembly:  XSharp.Core (in XSharp.Core.dll) Version: 2.19
Syntax
 FUNCTION DiskFree(
	cDrive AS STRING
) AS INT64
Request Example View Source

Parameters

cDrive
Type: String
The letter of the disk drive to query, for example "C:", "A:". The drive can also be identified by a number, where 1 is drive A, 2 is B, 3 is C, and so on.
If you do not specify a drive, the Windows default is used.

Return Value

Type: Int64
The number of bytes of empty space on the specified disk drive.
Remarks
DiskFree() determines the number of available bytes remaining on the specified disk drive.
It is useful when copying or sorting to another drive to determine if there is enough space available before initiating the operation.
Examples
This example is a function that demonstrates the use of DiskFree() to back up a database file to another drive:
X#
 1FUNCTION BackUp(cTargetFile, cTargetDrive)
 2    LOCAL nSpaceNeeded
 3    LOCAL lSuccess := FALSE
 4    // Calculate the size of the open file
 5    nSpaceNeeded := Integer((RecSize() * ;
 6                    LastRec()) + Header() + 1)
 7    IF DiskFree(cTargetDrive) < nSpaceNeeded
 8        lSuccess := FALSE
 9    ELSE
10        // Close the database file before copying
11       DBCloseArea()
12        FCopy("sales.dbf", cTargetDrive + ":"+ cTargetFile)
13        lSuccess := TRUE
14    ENDIF
15    RETURN lSuccess
See Also