Share via


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

The My.Computer.FileSystem.GetDriveInfo Method provides a DriveInfo object that can be queried for information about a drive on a computer. You can use the TotalFreeSpace property to determine the amount of space on a drive. Attempting to access the property without sufficient permission throws a SecurityException exception.

Note

  The options available in dialog boxes, and the names and locations of menu commands you see, might differ from what is described in Help, depending on your active settings or edition. This Help page was written with General Development Settings in mind. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To determine the amount of free space on a drive

  • Use the TotalFreeSpace property to determine the amount of free space, as illustrated in the following code:

    Dim cdrive As System.IO.DriveInfo
    cdrive = My.Computer.FileSystem.GetDriveInfo("C:\")
    MsgBox("Total free space: " & CStr(cdrive.TotalFreeSpace))
    

    This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in File system - Processing Drives, Folders, and Files. For more information, see How to: Insert Snippets Into Your Code (Visual Basic).

See Also

Tasks

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

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

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

Reference

My.Computer.FileSystem.GetDriveInfo Method

DriveInfo