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

FileSystemObject.GetDrive Method

Syntax

                  oFileSysObj.GetDrive(drivespecifier)
oFileSysObj

Use: Required

Data Type: FileSystemObject object

A FileSystemObject object.

drivespecifier

Use: Required

Data Type: 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 and 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 calling GetDriveName to extract the drive ...

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