Properties of the Drive Object

The Drive object provides access to the properties of the specified drive on a computer or a server. The following lines of code create a reference to the Drive object:

Set fs = CreateObject("Scripting.FileSystemObject") Set objDrive = fs.GetDrive("C:\")

You will find several procedure examples that use the Drive object in the table below.

Table 8-6: Selected properties of the Drive object

Property Description

AvailableSpace Available space in bytes FreeSpace Same as AvailableSpace

DriveLetter The drive letter (without the colon)

DriveType The type of drive:

0 - Unknown

1 - Removable

Sub CDROM_DriveLetter() Const CDROM = 4 Dim fs, colDrives

Set fs = CreateObject("Scripting.FileSystemObject") Set colDrives = fs.Drives

For Each Drive In colDrives

If Drive.DriveType = CDROM Then MsgBox "The CD-ROM Drive: " & _ Drive.DriveLetter

End If


End Sub

FileSystem File system, such as FAT, NTFS, or CDFS

IsReady Returns True if the appropriate media (CD-ROM disk) is inserted and ready for access

Function IsCDROMReady(strDriveLetter) Dim fs, objDrive

Set fs = CreateObject("Scripting.FileSystemObject") Set objDrive = fs.GetDrive(strDriveLetter)

IsCDROMReady = (objDrive.DriveType = 4) And _

objDrive.IsReady = True ' run this function from the Immediate window ' by entering: ?IsCDROMReady("D:") End Function




The path of the root folder


Serial number of the drive


Total drive size in bytes

0 0

Post a comment