Name
FileSystemObject.GetDrive Method
Syntax
oFileSysObj.GetDrive(drivespecifier)
oFileSysObjUse: Required
Data Type: FileSystemObject object
A FileSystemObject object.
drivespecifierUse: 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
drivespecifieris 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
drivespecifieris 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
drivespecifierstring 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 ...
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