Export (0) Print
Expand All

DriveInfo Class

Provides access to information on a drive.

Namespace:  System.IO
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class DriveInfo _
	Implements ISerializable
'Usage
Dim instance As DriveInfo

This 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 to determine the capacity and available free space on the drive.

The following code example demonstrates the use of the DriveInfo class to display information about all of the drives on the current system.

Imports System
Imports System.IO

Class Test
    Public Shared Sub Main()
        Dim allDrives() As DriveInfo = DriveInfo.GetDrives()

        Dim d As DriveInfo
        For Each d In allDrives
            Console.WriteLine("Drive {0}", d.Name)
            Console.WriteLine("  File type: {0}", d.DriveType)
            If d.IsReady = True Then
                Console.WriteLine("  Volume label: {0}", d.VolumeLabel)
                Console.WriteLine("  File system: {0}", d.DriveFormat)
                Console.WriteLine( _
                    "  Available space to current user:{0, 15} bytes", _
                    d.AvailableFreeSpace)

                Console.WriteLine( _
                    "  Total available space:          {0, 15} bytes", _
                    d.TotalFreeSpace)

                Console.WriteLine( _
                    "  Total size of drive:            {0, 15} bytes ", _
                    d.TotalSize)
            End If 
        Next 
    End Sub 
End Class 
'This code produces output similar to the following: 

'Drive A:\ 
'  File type: Removable 
'Drive C:\ 
'  File type: Fixed 
'  Volume label:  
'  File system: FAT32 
'  Available space to current user:     4770430976 bytes 
'  Total available space:               4770430976 bytes 
'  Total size of drive:                10731683840 bytes  
'Drive D:\ 
'  File type: Fixed 
'  Volume label:  
'  File system: NTFS 
'  Available space to current user:    15114977280 bytes 
'  Total available space:              15114977280 bytes 
'  Total size of drive:                25958948864 bytes  
'Drive E:\ 
'  File type: CDRom 

'The actual output of this code will vary based on machine and the permissions 
'granted to the user executing it.

System.Object
  System.IO.DriveInfo

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft