General discussion

Locked

Doubt in VB

By vramji ·
How to write a Program to know about remaining free space in HardDisk in VB?

I want to know about free space available in Harddisk. How to write a program? Is there any function?

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Doubt in VB

by Bill_Brower In reply to Doubt in VB

You can use the FileSystemObject in VB to get drive information. You must include a reference to the Microsoft Scripting Runtime in your project to use FSO. The following code was pulled from MSDN (Visual Basic Concepts book):

Private Sub Command3_Click()
Dim fso As New FileSystemObject, drv As Drive, s As String
Set drv = fso.GetDrive(fso.GetDriveName("c:"))
s = "Drive " & UCase("c:") & " - "
s = s & drv.VolumeName & vbCrLf
s = s & "Total Space: " & FormatNumber(drv.TotalSize / 1024, 0)
s = s & " Kb" & vbCrLf
s = s & "Free Space: " & FormatNumber(drv.FreeSpace / 1024, 0)
s = s & " Kb" & vbCrLf
MsgBox s
End Sub

Collapse -

Doubt in VB

by vramji In reply to Doubt in VB

Thank you, it will help to me

Collapse -

Doubt in VB

by sl-campbell In reply to Doubt in VB

This will return the number of free MBs:

Put in the declarations section of a standard module:

Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" _
(ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, _
lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long

'add this function
Public Function FreeDiskSpace(sDrive As String) As Single
'Returns MBs Free

Dim lBytesPerSector As Long
Dim lSectorsPerCluster As Long
Dim lNumOfFreeClusters As Long
Dim lTotalNumOfClusters As Long

If GetDiskFreeSpace(Left$(sDrive, 1) + ":\", lSectorsPerCluster, lBytesPerSector, lNumOfFreeClusters, lTotalNumOfClusters) Then

FreeDiskSpace = lNumOfFreeClusters / 1000000000 * lSectorsPerCluster * lBytesPerSector
End If
End Function

Call like this:
Debug.Print FreeDiskSpace("C")

Collapse -

Doubt in VB

by vramji In reply to Doubt in VB

Thank you, it will help to me

Collapse -

Doubt in VB

by vramji In reply to Doubt in VB

This question was closed by the author

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums