logo VB.Net - Disk Drives
Guide Contents
DigitalDan Home Page

Get List of Disk Drives
List every disk drive on a computer including floppy, CD, Hard-Disk, SSD etc.
 
Private Shared Function Get_All_Drives() As List(Of String)
Dim ret As New List(Of String)
Try
For Each d As DriveInfo In DriveInfo.GetDrives
ret.Add(d.Name)
Next
Catch ex As Exception
ret = {ex.Message}.ToList
End Try
Return ret
End Function

 
Get Available Disk Drives
This function will only list disk drives that can be used. It will ignore unplugged memory-cards etc.
 
Private Shared Function Get_Available_Drives() As List(Of String)
Dim ret As New List(Of String)
Try
For Each d As DriveInfo In DriveInfo.GetDrives
If d.IsReady Then
ret.Add(d.Name)
End If
Next
Catch ex As Exception
ret = {ex.Message}.ToList
End Try
Return ret
End Function

 
Get Information about a Disk Drive
Private Shared Function GetDriveInfo() As List(Of String)
Dim ret As New List(Of String)
Try
Dim di As New DriveInfo("c:\")
ret.Add("Free Space (Long) = " & di.AvailableFreeSpace.ToString)
ret.Add("Drive format (String) = " & di.DriveFormat)
Select Case di.DriveType
Case DriveType.CDRom : ret.Add("Drive Type (DriveType) = CD Rom")
Case DriveType.Fixed : ret.Add("Drive Type (DriveType) = Fixed")
Case DriveType.Network : ret.Add("Drive Type (DriveType) = Network")
Case DriveType.NoRootDirectory : ret.Add("Drive Type (DriveType) = Does not have a root directory")
Case DriveType.Ram : ret.Add("Drive Type (DriveType) = RAM")
Case DriveType.Removable : ret.Add("Drive Type (DriveType) = Removeable")
Case DriveType.Unknown : ret.Add("Drive Type (DriveType) = Unknown")
End Select
ret.Add("Drive is ready to use (Boolean) = " & di.IsReady.ToString)
ret.Add("Drive Name (String) = " & di.Name)
ret.Add("Drive Total Size (Long) = " & di.TotalSize.ToString)
ret.Add("Drive Volume Label (String) = " & di.VolumeLabel)
If Not (di.DriveType = DriveType.NoRootDirectory) _
AndAlso (Not di.DriveType = DriveType.Unknown) _
AndAlso di.Name.Length > 0 Then
ret.Add("Drive Root Folder (String) = " & Mid(di.Name, 1, 1) & ":\")
End If
Catch ex As Exception
ret.Add("Error = " & ex.Message)
End Try
Return ret
End Function

DigitalDan.co.uk ... Hits = 329