FileSystemObject.GetDrive Method (VB6)

Syntax

oFileSysObj.GetDrive(drivespecifier)

oFileSysObj

Use: Required

Data Type: FileSystemObject object

Any object variable returning 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 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

  • 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 from the fully qualified path. For example:

    Dim oFileSys As New FileSystemObject
    Dim oDrive As Drive
    
    sPath = oFileSys.GetAbsolutePathName(sPath)
    If oFileSys.FolderExists(sPath) Then
       Set oDrive = _
           oFileSys.GetDrive(oFileSys.GetDriveName(sPath))
    End If
  • If drivespecifier is a network drive or share, you should use the DriveExists method to confirm the required drive is available prior to calling the GetDrive method.

  • You must use the Set statement to assign the Drive object ...

Get VB & VBA in a Nutshell: The Language 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.