VB.Net program to read the list of available disk drives

Here, we are going to learn how to read the list of available disk drives in VB.Net?
Submitted by Nidhi, on January 06, 2021 [Last updated : March 08, 2023]

VB.Net – List of Available Disk Drives

Here, we will use DriveInfo class to read the list of available disk drives and print the drive name, drive type, and size of the drive on the console screen.

Program/Source Code:

The source code to read the list of available disk drives is given below. The given program is compiled and executed successfully.

VB.Net code to read the list of available disk drives

'Vb.Net program to read the list of available disk drives.

Imports System.IO

Module Module1
    Class Sample
        Shared Sub ReadDrives()
            Dim drvlist() As DriveInfo = DriveInfo.GetDrives()

            For Each drv In drvlist
                Console.WriteLine("Drive Name: {0}", drv.Name)
                Console.WriteLine(vbTab & "Drive Type: {0}", drv.DriveType)

                If (drv.IsReady = True) Then
                    Dim size As Long = 0
                    size = (drv.TotalSize) / (1024 * 1024 * 1024)
                    Console.WriteLine(vbTab & "Size of drive in GB {0}", size & vbCrLf)
                End If
            Next
        End Sub
    End Class

    Sub Main()
        Sample.ReadDrives()
    End Sub
End Module

Output

Drive Name: C:\
        Drive Type: Fixed
        Size of drive in GB 476

Press any key to continue . . .

Explanation

In the above program, we created a class module Module1 that contains a class Sample and a Main() function. The Sample class contains a shared method ReadDrives().

In the ReadDrives() method, we read the list of available disk drives and print the drive name, drive type, and size of the drive on the console screen.

The Main() method is the entry point of the program, here we called the shared method ReadDrives().



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.