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

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 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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.