Will from London
Board Regular
- Joined
- Oct 14, 2004
- Messages
- 220
Hi
I have a custom function that displays the size (in KB, MB, GB etc) of folders. I use it to record the size of folders on servers. Some folders are compressed on NTFS servers so what would be really useful is if I could show the "size on disk" property referred to in the properties box in windows explorer when one right-clicks on a folder or file.
My existing code is:
Any help much appreciated. Regards
Will
I have a custom function that displays the size (in KB, MB, GB etc) of folders. I use it to record the size of folders on servers. Some folders are compressed on NTFS servers so what would be really useful is if I could show the "size on disk" property referred to in the properties box in windows explorer when one right-clicks on a folder or file.
My existing code is:
Code:
Function DirSize(dirName As String, Scaler As String) As Variant
Dim fileSys As Object
Dim folderName As Object
If Right(dirName, 1) <> "\" Then dirName = dirName & "\"
If dirName = "\" Then
DirSize = "# - Folder not recognised"
ElseIf Dir(dirName) = "" Then
DirSize = "# - Folder not found"
Else
Set fileSys = CreateObject("Scripting.FileSystemObject")
Set folderName = fileSys.GetFolder(dirName)
Select Case UCase(Scaler)
Case "B"
DirSize = folderName.Size / (1024 ^ 0)
Case "K"
DirSize = folderName.Size / (1024 ^ 1)
Case "M"
DirSize = folderName.Size / (1024 ^ 2)
Case "G"
DirSize = folderName.Size / (1024 ^ 3)
Case "T"
DirSize = folderName.Size / (1024 ^ 4)
Case Else
DirSize = "# - Scaler not recognised"
End Select
Set fileSys = Nothing
Set folderName = Nothing
End If
End Function
Any help much appreciated. Regards
Will