Vbscript / Files And Folders / Folder Size Scanner
This script demonstrates use of the windows folder selection dialogue box and recursive folder scanning to report on the size of all subfolders below a specified target folder.
On Error Resume Next Set objFSO = CreateObject("Scripting.FileSystemObject") Set oShell = CreateObject ("Shell.Application") Set oFolder = oShell.BrowseForFolder (0, "Select Target Folder for Folder Size Scanning", (0)) sTitle = oFolder.Title If (Err.Number = 0) Then Set oParent = oFolder.ParentFolder Set cItems = oParent.Items For Each oItem In cItems If oItem.IsFolder = True Then If (StrComp(oItem.Name, sTitle, 1) = 0) Then strOutput = "" dirScan(oItem.Path) End If End If Next End If Wscript.Echo strOutput Set oShell = Nothing Set oFolder = Nothing Set cItems = Nothing Set oItem = Nothing Sub dirScan(dir)
Set objDir = objFSO.getFolder(dir) intDirSize = objDir.Size strOutput = strOutput & vbCRLF & dir & " - " & byteValue(intDirSize) 'For each subfolder recall subroutine For Each objSubDir in objDir.SubFolders dirScan(objSubDir.Path) Next End Sub function byteValue(val)
unit = " B" If val > 1000 Then val = val/1024 unit = " KB" If val > 1000 Then val = val/1024 unit = " MB" If val > 1000 Then val = val/1024 unit = " GB" If val > 1000 Then val = val/1024 unit = " TB" End If end If End If end If byteValue = int(val) & unit End function
Please note that a disclaimer applies to any code on this page.
|