Share via


My.Computer.FileSystem.GetDriveInfo Method

Returns a DriveInfo object for the specified drive.

' Usage
Dim value As System.IO.DriveInfo = My.Computer.FileSystem.GetDriveInfo(drive)
' Declaration
Public Function GetDriveInfo( _
   ByVal drive As String _
) As System.IO.DriveInfo

Parameters

  • drive
    String. Drive to be examined. Required.

Return Value

DriveInfo

Exceptions

The following conditions may cause an exception:

  • The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \\.\) (ArgumentException).

  • The path is not valid because it is Nothing (ArgumentNullException).

  • The path exceeds the system-defined maximum length (PathTooLongException).

  • A file or folder name in the path contains a colon (:) or is in an invalid format (NotSupportedException).

  • The user lacks necessary permissions to view the path (SecurityException).

Remarks

The DriveInfo class models a drive and provides methods and properties to query for drive information. Use DriveInfo to determine what drives are available, and what type of drives they are. You can also query the property to determine the capacity and available free space on the drive.

Tasks

The following table lists examples of tasks involving the My.Computer.FileSystem.GetDriveInfo method.

To

See

Determine a drive's volume label

How to: Determine a Drive's Volume Label in Visual Basic

Determine a drive's type

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

Determine a drive's total space

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

Determine a drive's physical free space

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

Determine a drive's root folder

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

Example

This example obtains a DriveInfo object for the C drive and uses it to display information about the drive.

Dim getInfo As System.IO.DriveInfo
getInfo = My.Computer.FileSystem.GetDriveInfo("C:\")
MsgBox("The drive's type is " & getInfo.DriveType)
MsgBox("The drive has " & getInfo.TotalFreeSpace & " bytes free.")

For information on the different drive types, see DriveType.

Requirements

Namespace:Microsoft.VisualBasic.MyServices

Class:FileSystemProxy (provides access to FileSystem)

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type

Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

Permissions

The following permission may be necessary:

Permission

Description

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

For more information, see Code Access Security and Requesting Permissions.

See Also

Reference

My.Computer.FileSystem Object

System.IO.DriveInfo

GetDriveInfo

DriveType

Other Resources

File, Directory, and Drive Properties in Visual Basic