Get Available Disk Space 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
No comments:
Post a Comment