Download text file
$IF 0
---------------------------- PowerBASIC/cc v1.0
---| DASoft |------------------------------------------
---------------------------- Code DATE: 1999-01-15
| FILE NAME drivenfo.bas | by
| | Don Schullian, Jr.
---------------------------- www.DASoftVSS.com
This code is placed into PUBLIC DOMAIN
-------------------------------------------------------------------------
PURPOSE: return info on logical drives
NOTES: Three of the 5 functions in this file are meant more as a
starting point than a finished product. Although they do return
usable data it would, IMO, be best to mold them into whatever
format was required by your program(s).
-------------------------------------------------------------------------
$ENDIF
$INCLUDE "WIN32API.INC"
DECLARE FUNCTION fGetLogicalDrives () AS STRING
DECLARE FUNCTION fGetDriveTypes () AS STRING
DECLARE FUNCTION fGetVerboseDriveType (BYVAL Drive AS STRING) AS STRING
DECLARE FUNCTION fDiskSize (BYVAL Drive AS STRING) AS QUAD
DECLARE FUNCTION fDiskFree (BYVAL Drive AS STRING) AS QUAD
'--------------------------
'-------------- TEST CODE --------------------------------------------------------------
'--------------------------
FUNCTION PBmain ()
PRINT "Logical Drive List: "; fGetLogicalDrives
PRINT "Logical Drive Types: "; fGetDriveTypes
PRINT
PRINT "INFO ON "; LEFT$(CURDIR$,1); " DRIVE"
PRINT fGetVerboseDriveType("")
PRINT FORMAT$(fDiskSize(""),"###,###,###,### bytes")
PRINT FORMAT$(fDiskFree(""),"###,###,###,### bytes free")
WAITKEY$
END FUNCTION
'--------------------------------
'-------------- THE REAL THING ----------------------------------------------------------
'--------------------------------
FUNCTION fGetLogicalDrives () AS STRING
DIM BitPos AS LOCAL LONG ' bit position in mask
DIM Dpos AS LOCAL LONG ' drive letter position in list
DIM DriveList AS LOCAL STRING * 26 ' list of drive letters
DIM DriveMask AS LOCAL LONG ' returned bit mask of drives
'-------------------------------
DriveMask = GetLogicalDrives ' get bit mask of all drives
'
FOR BitPos = 0 TO 25 ' check low 26 bits
IF ISTRUE BIT(DriveMask,BitPos) THEN ' this is a drive letter
INCR Dpos ' next letter position
ASC(DriveList,Dpos) = ( BitPos + 65 ) ' set the drive letter
END IF '
NEXT '
'-------------------------------
FUNCTION = RTRIM$(DriveList) 'RETURN list of all drive letters
END FUNCTION
'
'---------------------------------------------------------------------------------------
'
FUNCTION fGetDriveTypes () AS STRING
DIM BitPos AS LOCAL LONG ' bit position in mask
DIM Dpos AS LOCAL LONG ' drive letter position in list
DIM zDrive AS LOCAL ASCIIz * 4 ' drive letter to send to API
DIM DriveList AS LOCAL STRING * 26 ' working string for values
DIM DriveMask AS LOCAL LONG ' returned bit mask of drives
DIM DriveType AS LOCAL LONG ' returned drive type zero -> six
'-------------------------------
DriveMask = GetLogicalDrives ' get bit mask of all drives
zDrive = " :\" ' set these once only
'
FOR BitPos = 0 TO 25 ' check low 26 bits
IF ISTRUE BIT(DriveMask,BitPos) THEN ' this is a drive letter
ASC(zDrive,1) = (BitPos+65) ' set drive letter eg: A:\
DriveType = GetDriveType(zDrive) ' get drive type value 0-6
INCR Dpos ' next letter position
ASC(DriveList,Dpos) = (DriveType + 48) ' set the drive type value (0-6)
END IF '
NEXT '
'-------------------------------
FUNCTION = RTRIM$(DriveList) 'RETURN list of all drive types
END FUNCTION
'
'---------------------------------------------------------------------------------------
'
FUNCTION fGetVerboseDriveType (BYVAL Drive AS STRING) AS STRING
DIM DriveLtr AS LOCAL ASCIIz * 4 ' drive letter to send to API
DIM DriveType AS LOCAL LONG ' returned drive type zero -> six
'
'-----------------------------------------------' verbage for drive types
DATA UNKNOWN, NO_ROOT_DIR, REMOVABLE ' values 0 - 2 (1 = error)
DATA FIXED, REMOTE, CDROM, RAMDISK ' values 3 - 6
'-----------------------------------------------'
IF ISFALSE LEN(Drive) THEN Drive = CURDIR$ ' use current drive
DriveLtr = LEFT$(Drive,1) & ":\" ' set ASCIIz value
DriveType = GetDriveType(DriveLtr) + 1 ' get drive type value 0-6 : add one
'
FUNCTION = READ$(DriveType) 'RETURN verbose drive type
END FUNCTION
'
'---------------------------------------------------------------------------------------
'
FUNCTION fDiskFree (BYVAL Drive AS STRING) AS QUAD
LOCAL BpS AS DWORD ' Bytes per Sector
LOCAL zDrive AS ASCIIz * 4 ' drive spec
LOCAL FCs AS DWORD ' Free Clusters
LOCAL SC AS DWORD ' Sectors per Cluster
LOCAL TCs AS DWORD ' Total Clusters
'
IF ISFALSE LEN(Drive) THEN Drive = CURDIR$ ' use current drive
zDrive = LEFT$(Drive,1) & ":\" ' set drive spec
GetDiskFreeSpace zDrive, SC, BpS, FCs, TCs ' get drive sector/cluster
'
FUNCTION = ( FCs * SC * BpS ) 'RETURN free bytes
END FUNCTION
'
'---------------------------------------------------------------------------------------
'
FUNCTION fDiskSize (BYVAL Drive AS STRING) AS QUAD
LOCAL BpS AS DWORD ' Bytes per Sector
LOCAL zDrive AS ASCIIz * 4 ' drive spec
LOCAL FCs AS DWORD ' Free Clusters
LOCAL SC AS DWORD ' Sectors per Cluster
LOCAL TCs AS DWORD ' Total Clusters
'
IF ISFALSE LEN(Drive) THEN Drive = CURDIR$ ' use current drive
zDrive = LEFT$(Drive,1) & ":\" ' set drive spec
GetDiskFreeSpace zDrive, SC, BpS, FCs, TCs ' get drive sector/cluster
'
FUNCTION = ( TCs * SC * BpS ) 'RETURN total drive size
END FUNCTION