logo  VB.Net - Get Disk Drives
This Chapter
Disk Drives
Chapters
Home Page
Colours, RGB
Computer Specifications
Dates&Times
Disk Drives
Files
Folders
GPS and OS Ref
VB.Net Forms
Image Files
If & Select
List/Array
Mathematics
NuGet
Sound
String Functions
Sun and Moon
User Controls
Validation
DigitalDan Sites
My Other Sites
Contact Site

Note
Some pages
may contain
inaccuracies
Hits=5
File Attributes
These functions return information about all disk drives which could be used by the host computer. Some drives may be installed but are unavailable at the moment e.g. A CD drive will not work unless there is a CD in the drive. Whilst all the drives can be identified, VB.Net cannot retrieve certain details (e.g. disk capacity) from drives that are not currently working.

Private Function ListDiskDrives() As List(Of Char)
 Dim ret As New List(Of Char)
 For Each d As IO.DriveInfo In IO.DriveInfo.GetDrives
  ret.Add(CChar(Mid(d.Name, 1, 1)))
 Next
 Return ret
End Function
'
Private Function IsDriveReadyToUse(driveletter As Char) As Boolean
 Dim d As DriveInfo = New DriveInfo(driveletter & ":\")
 Return d.IsReady
End Function
'
Private Function GetDriveType(driveletter As Char) As String
 Dim d As DriveInfo = New DriveInfo(driveletter & ":\")
 Return d.DriveType.ToString
End Function
'
Private Function GetDriveRootDirectory(driveletter As Char) As String
 Dim d As DriveInfo = New DriveInfo(driveletter & ":\")
 Return d.RootDirectory.ToString
End Function
'
Private Function GetDriveAvailableFreeSpace(driveletter As Char) As Long
 Dim d As DriveInfo = New DriveInfo(driveletter & ":\")
 If Not d.IsReady Then Return 0
 Return d.AvailableFreeSpace
End Function
'
Private Function GetDriveTotalFreeSpace(driveletter As Char) As Long
 Dim d As DriveInfo = New DriveInfo(driveletter & ":\")
 If Not d.IsReady Then Return 0
 Return d.TotalFreeSpace
End Function
'
Private Function GetDriveTotalSize(driveletter As Char) As Long
 Dim d As DriveInfo = New DriveInfo(driveletter & ":\")
 If Not d.IsReady Then Return 0
 Return d.TotalSize
End Function
'
Private Function GetDriveFormat(driveletter As Char) As String
 Dim d As DriveInfo = New DriveInfo(driveletter & ":\")
 If Not d.IsReady Then Return 0
 Return d.DriveFormat
End Function
'
Private Function GetDriveVolumeLabel(driveletter As Char) As String
 Dim d As DriveInfo = New DriveInfo(driveletter & ":\")
 If Not d.IsReady Then Return 0
 Return d.VolumeLabel
End Function
  

DigitalDan.co.uk