SoFunction
Updated on 2025-03-10

VBS Tutorial: Method - GetDriveName Method

GetDriveName method

Returns a string containing the drive name in the specified path.

object.GetDriveName(path)

parameter

object

Required option. Should be the name of FileSystemObject.

path

Required option. Specifies the path to return the drive name of its component.

illustrate

If the drive cannot be determined,GetDriveNameThe method returns a zero-length string ("").

The following example shows how to use itGetDriveNamemethod:

 Function GetAName(DriveSpec)  Dim fso  Set fso = CreateObject("")  GetAName = (Drivespec)End Function

Notice GetDriveNameMethods can only be providedpathThe string of . It cannot attempt to analyze a path, nor can it check if the specified path exists.