How to: Determine a Drive's Root Directory in Visual Basic

The GetDriveInfo method provides a DriveInfo object that can be queried for information about a drive on a computer. You can use the RootDirectory property to determine the root directory. Attempting to access the property without sufficient permission throws a SecurityException exception.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To determine a drive's root directory

  • Use the RootDirectory property to determine the root directory, as illustrated in the following code.

    Dim cdrive As System.IO.DriveInfo
    cdrive = My.Computer.FileSystem.GetDriveInfo("C:\")
    MsgBox(cdrive.RootDirectory)
    

See Also

Tasks

How to: Determine a Drive's Total Space in Visual Basic

How to: Determine a Drive's Type in Visual Basic

Reference

GetDriveInfo

DriveInfo