FileSystemObject : GetDriveName Method


Returns drive name, corresponding to the file name.

Format : 

objectOfFileSystemObject. GetDriveName(filepath)

  • objectOfFileSystemObject : As the names says, it’s a FileSystemObject.
  • filepath
    • Mandatory
    • Type:     String
    • filepath , whose parent drive to be return.

Function FnGetDriveName (strFilePath)
      Set fso = CreateObject("Scripting.FileSystemObject")
      strDriveName = fso. GetAName (strFilePath)      
      FnGetDriveName = strDriveName

End Function

Msgbox FnGetDriveName (“c:\NewFolder\file.txt”)

Output : C


Leave a Comment