O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Drives Collection Object

Returned by

FileSystemObject.Drives property

Createable

No

Library

Microsoft Scripting Runtime

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 read-only.

The Drives collection cannot be created; instead, it is returned by the Drives property of the FileSystemObject object, as the following code fragment illustrates:

Dim oFS, oDrives
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oDrives = oFS.Drives

For an overview of the filesystem object model, including the library reference needed to access it, see the “File System Object Model” entry.

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 exist 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required