Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
DRIVETYPE()
This function reports the type of drive specified, reading only the first letter of the supplied parameter. It duplicates, with one exception, the DRIVETYPE()
function of FoxTools, which itself is just a wrapper around the Win32 API function, GetDriveType().
nType = DriveType( cDriveLetter )
Parameter |
Value |
Meaning |
cDrive |
A - Z |
The drive whose type is to be checked. |
nType |
0 |
Under VFP 3.x and 5.x, no such drive. |
1 |
In VFP 6.0 and later, no such drive. |
|
2 |
Floppy drive. |
|
3 |
Hard disk. |
|
4 |
Removable or network drive. |
|
5 |
CD-ROM. |
|
6 |
RAM disk. |
This function is handy to have, but we don’t understand why we have it built into our database management language. It is easy enough to access it directly from the underlying Win32 API, as shown in the second example below. Just dBloat, as far as we can tell…
Take the answers provided with a grain of salt. Depending on how vendors have designed their drivers to interact with the operating system, your results may vary. For example, Iomega Jaz and ZIP drives respond as floppies (type 2), but if the operator uses the supplied Iomega software to make the disk “non-removable,” the drive shows as a hard disk (type 3). Also, being a network drive outweighs other considerations, so a Jaz drive checked through a network mapping returns 4. Use DISKSPACE()
, SYS(2020) and SYS(2022) to determine what kind of drive you’re working with.
VFP 3.x and 5.x with FoxTools reports 0 for unknown drives. VFP 6.0 and later report 1 instead. |
And, of course, it doesn't always work. DriveType() doesn't work with UNC paths, returning 0 or 1 for an unknown drive. That's undoubtedly because the function looks only at the first letter of the string you pass it. |
* Returns 2 for most folks.
? DriveType("A")
* This code provides the same functionality for VFP 3 or 5
* on any Win32 Platform.
LPARAMETERS tcDrive
DECLARE Integer GetDriveType ;
IN WIN32API ;
AS WGDT ;
STRING DriveLetter
RETURN WGDT(LEFT(tcDrive,1) + ":")
* Z: is mapped as a ZIP drive on the network.
? DriveType("\\Orion\ZIPDrive") && 1: unknown
? DriveType("Z") && 4: removable/network drive
* On the local machine, this drive displays type 2 - floppy.
SET DEFAULT TO Z
? SYS(2020) && 100431872 - 95.8 Mb
? SYS(2022, "Z") && 2048 - 2K cluster size