| Drives Collection Object (VB6) |
Description
All drives connected to the current machine are included in the Drives collection, even those that aren't currently ready (like removable media drives with no media inserted in them). The Drives collection object is zero-based and is read-only.
See the File System object model entry for an overview, including the library reference needed to access it.
Createable
No
Returned by
FileSystemObject.Drives property
Properties
Count
Data Type: Long
Returns the number of Drive objects in the collection.
Item
Syntax: oDrives.Item(key)
Data Type: Drive object
Returns a Drive object whose key is key, the drive letter. This is an unusual collection, since the drive's index value (its ordinal position in the collection) can't be used; attempting to do so generates runtime error 5, "Invalid procedure call or argument." Since attempting to retrieve a Drive object for a drive that doesn't exists generates runtime error 68, it's a good idea to call the FileSystemObject object's DriveExists method beforehand.
Example
Dim ofsFileSys As FileSystemObject
Dim ofsDrives As Drives
Dim ofsDrive As Drive
Set ofsFileSys = New FileSystemObject
Set ofsDrives = ofsFileSys.Drives
Set ofsDrive = ofsDrives.Item("C")
MsgBox ofsDrive.DriveType
Set ofsDrive = Nothing
Set ofsDrives = Nothing
Set ofsFileSys = Nothing
See Also
- Drive Object, FileSystemObject.Drives Property
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access