PDA

View Full Version : Available Drive Space / Used Space



JimHol
12-27-2012, 02:22 PM
Rick,

Thanks for you help in the past with the code below, it has worked great for me. Is it possible to do something similar to also determine the amount of used space in a particular folder on the drive?

"\\networkdrive\thisproject"

PS. I removed the "Replace" statements from your code to make it functional for my network.



Private Declare Function GetDiskFreeSpaceEx Lib "kernel32" _
Alias "GetDiskFreeSpaceExA" _
(ByVal lpDirectoryName As String, _
lpFreeBytesAvailableToCaller As Currency, _
lpTotalNumberOfBytes As Currency, _
lpTotalNumberOfFreeBytes As Currency _
) As Long

Function TotalBytes(ByVal DriveLetter As String) As Currency
Dim BytesAvailableToCaller As Currency, FreeBytes As Currency
GetDiskFreeSpaceEx DriveLetter, BytesAvailableToCaller, TotalBytes, FreeBytes
End Function

Function FreeBytes(ByVal DriveLetter As String) As Currency
Dim BytesAvailableToCaller As Currency, TotalBytes As Currency
GetDiskFreeSpaceEx DriveLetter, BytesAvailableToCaller, TotalBytes, FreeBytes
End Function

Rick Rothstein
12-28-2012, 11:41 AM
Thanks for you help in the past with the code below, it has worked great for me. Is it possible to do something similar to also determine the amount of used space in a particular folder on the drive?

\\networkdrive\thisproject (file://\\networkdrive\thisproject)

I do not have access to a network, so I cannot test this code out, but I think it should work with that type of folder reference (you will have to try it out and let me know)...

Function FolderSize(FolderPath As String) As Variant
Dim FS As Object, Folder As Object
Set FS = CreateObject("Scripting.FileSystemObject")
Set Folder = FS.GetFolder(FolderPath & IIf(Right(FolderPath, 1) = "\", "", "\"))
FolderSize = Folder.Size
End Function

JimHol
12-28-2012, 06:57 PM
Thanks Rick,

I am sure this code will work as well as the other code. I will give it a try first thing tomorrow.

Thanks again,
Jim