| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Changes the current disk drive.
DiskChange( <cDrive> ) --> lSuccess
The funtion returns .T. (true) if the drive <cDrive> is selected as current drive, otherwise .F. (false) is returned.
The function attempts to change the current disk drive and returns .T. (true) when the operation is successful.
Note: DiskChange() uses operating system functionalities. If a disk drive exists but has no disk inserted, the operating system prompts the user for inserting a disk.
To suppress this behavior, call SetErrorMode() and pass 1 to it.
| See also: | CurDrive(), CurDir(), DirChange(), DiskSpace(), IsDisk(), SetErrorMode() |
| Category: | Directory functions , File functions , xHarbour extensions |
| Source: | rtl\dirdrive.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example demonstrates basic usage of DiskChange() and
// includes a user defined function that queries disk drives.
PROCEDURE Main
LOCAL aDisk, cDisk
? CurDrive() // result: C
? CurDir() // result: xhb\tests
? DiskChange( "D" ) // result: .T.
? CurDrive() // result: D
? CurDir() // result: apps\data
? DiskChange( "K") // result: .F.
? CurDrive() // result: D
? CurDir() // result: apps\data
aDisk := GetDrives()
FOR EACH cDisk IN aDisk
? cDisk
END
RETURN
FUNCTION GetDrives()
LOCAL cDrive := CurDrive()
LOCAL aDrives := {}
LOCAL nDrive := 1
FOR nDrive := 1 TO 26
IF DiskChange( Chr( 64 + nDrive ) )
AAdd( aDrives, Chr( 64 + nDrive ) )
ENDIF
NEXT
DiskChange( cDrive )
RETURN aDrives
http://www.xHarbour.com