Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Folder Size Scanner
 

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.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
          - Auto Copy Files From Cdrom
          - Backup My Documents
          - Cleanup Filenames
          - File Properties
          - File Server Report
          - File Type Report Scan
          - Find And Replace Filename Text
          - Find And Replace Text In Files
          - Folder Size Scanner
          - Rename Files Find And Remove Text
          - Rename Files Find And Replace Text
          - Replace Folder Ntfs Security Permissions
          - Simple File Report
          - Sort And Move Files To Folders
          - Windows File Locations
     - General
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers