.

Tuesday, January 6, 2009

Get Free Disk Space in all drives using VB.Net

Sub GetSpaceInDrives()

'Dim oDinfo As DriveInfo

Dim oDrvs() As DriveInfo = DriveInfo.GetDrives

For Each Drv In oDrvs

If Drv.IsReady Then

MsgBox(Drv.Name & " " & Drv.AvailableFreeSpace.ToString)

End If

Next

End Sub

The statement

Dim oDrvs() As DriveInfo = DriveInfo.GetDrives

retrieves the drive names of all logical drives on a computer.

The IsReady property returns true if the drive is ready; false if the drive is not ready. If this check is not done then you will get System.IO.IOException was unhandled Message="The device is not ready. " exception.

AvailableFreeSpace property indicates the amount of free space available on the drive. Note that this number may be different from the TotalFreeSpace number because this property takes into account disk quotas

1 comment:

conanima said...

hi bhavi i viewed your post and its very useful to me, i like to share my link with your blog.visit my walkitz.blogspot.com

.