Name

FileSystemObject.GetDrive Method

Syntax

                  oFileSysObj.GetDrive(drivespecifier)
oFileSysObj

Use: Required

Data Subtype: FileSystemObject object

Any object variable returning a FileSystemObject object.

drivespecifier

Use: Required

Data Subtype: String

A drive name, share name, or network path.

Return Value

A Drive object.

Description

Obtains a reference to a Drive object for the specified drive.

Rules at a Glance

  • If drivespecifier is a local drive or the letter of a mapped drive, it can consist of only the drive letter (e.g., “C”), the drive letter with a colon (“C:”), or the drive letter and path to the root directory (e.g., “C:\”) without generating a runtime error.

  • If drivespecifier is a share name or network path, GetDrive ensures that it exists as part of the process of creating the Drive object; if it doesn’t, the method generates runtime error 76, “Path not found.”

  • If the specified drive isn’t connected or doesn’t exist, runtime error 67, “Device unavailable,” occurs.

Programming Tips & Gotchas

  • Individual drive objects can be retrieved from the Drives collection by using the Drives property. This is most useful, though, if you want to enumerate the drives available on a system. In contrast, the GetDrive method provides direct access to a particular Drive object.

  • If you are deriving the drivespecifier string from a path, you should first use GetAbsolutePathName to insure that a drive is present as part of the path. Then you should use FolderExists to verify that the path is valid before ...

Get VBScript in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.