RonQ Posted March 14, 2004 Posted March 14, 2004 Hello, simple question... How do I get the free space of a drive, example "c:" 2GB, "d:" 130 Mb... etc. Thanks, Ronq. Quote
*Experts* DiverDan Posted March 15, 2004 *Experts* Posted March 15, 2004 The simpliest way is to first add a reference to Interop.Scripting.dll in your project. Then Dim fso As New Scripting.FileSystemObject() Dim drv As Scripting.Drive Dim drvInfo As String For Each drv In fso.Drives 'get drive letter drvInfo = drv.DriveLetter & ": " If Not drv.IsReady Then 'get drive type Select Case drv.DriveType Case Scripting.DriveTypeConst.Removable drvInfo &= "3-1/2 Floppy Drive" 'drvInfo &= "Removable Drive" Case Scripting.DriveTypeConst.CDRom drvInfo &= "CD Rom Drive" Case Scripting.DriveTypeConst.RamDisk drvInfo &= "Ram Disk" Case Scripting.DriveTypeConst.Remote drvInfo &= "Network Drive" Case Scripting.DriveTypeConst.UnknownType drvInfo &= "Unknown Drive" End Select If drv.DriveType <> Scripting.DriveTypeConst.Fixed Then sysInfo(item, 0) = drvInfo sysInfo(item, 1) = " " item += 1 sysInfo(item, 0) = " " sysInfo(item, 1) = " " item += 1 End If ElseIf drv.IsReady Then 'get drive type Select Case drv.DriveType Case Scripting.DriveTypeConst.Removable drvInfo &= "3-1/2 Floppy Drive" 'drvInfo &= "Removable Drive" Case Scripting.DriveTypeConst.CDRom drvInfo &= "CD Rom Drive" Case Scripting.DriveTypeConst.RamDisk drvInfo &= "Ram Disk" Case Scripting.DriveTypeConst.Remote drvInfo &= "Network Drive" Case Scripting.DriveTypeConst.UnknownType drvInfo &= "Unknown Drive" Case Scripting.DriveTypeConst.Fixed drvInfo &= "Local Drive" End Select If drv.DriveType <> Scripting.DriveTypeConst.Fixed Then sysInfo(item, 0) = drvInfo sysInfo(item, 1) = drv.VolumeName item += 1 sysInfo(item, 0) = " " sysInfo(item, 1) = " " item += 1 Else 'hard drive information sysInfo(item, 0) = drvInfo sysInfo(item, 1) = "Volume Name: " & drv.VolumeName item += 1 sysInfo(item, 0) = " " sysInfo(item, 1) = "Total Size: " & Math.Round(Val(drv.TotalSize) / 1000000000, 2) & " GB" item += 1 sysInfo(item, 0) = " " sysInfo(item, 1) = "Free Space: " & Math.Round(Val(drv.FreeSpace) / 1000000000, 2) & " GB" item += 1 sysInfo(item, 0) = " " sysInfo(item, 1) = "Used Space: " & Math.Round((Val(drv.TotalSize) - Val(drv.FreeSpace)) / 1000000000, 2) & " GB" item += 1 sysInfo(item, 0) = " " sysInfo(item, 1) = "File System: " & drv.FileSystem item += 1 sysInfo(item, 0) = " " sysInfo(item, 1) = "Serial Number: " & drv.SerialNumber item += 1 sysInfo(item, 0) = " " sysInfo(item, 1) = " " item += 1 End If End If sysInfo(item, 1) is a 2D array I use to populate a listview, but of course, you can use anything other method of displaying the drive info. Hope that gives you an idea Dan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
RonQ Posted March 15, 2004 Author Posted March 15, 2004 thanks for your answer, but... I can't find Interop.Scripting.dll, is a file or a namespace, can you tell me the full namespace/file name?? Bye, Ronq. Quote
*Experts* DiverDan Posted March 15, 2004 *Experts* Posted March 15, 2004 From the VS Studio menu click Project, Add Reference, Com, Microsoft Scripting DLL. Microsoft Scripting DLL is Interop.Scripting.dll. Hope that helps Dan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.