Avatar of Nick_D
Nick_D asked on

Script to show folder sizes


I have a file server and I would like to be able to run a script to show the current size of the folders on a particular partition.  I would also like to have another script to be able to then give more detailed information about larger files, for example, the size of all the sub directories in that folder.

I am fairly new to scripting so any help would be appreciated.


Avatar of undefined
Last Comment

8/22/2022 - Mon

Paste the script below into a text file with a .vbs extension.  Customize the value of the strFolder variable with the location of the folder to check under.  Running the script will generate a comma-delimited text file containing each subfolder's path and size in MB.

On Error Resume Next
Const ForAppending = 8
Const intMB = 1048576
strFolder = "c:\"
strReport = "FolderSizeReport.csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReport = objFSO.OpenTextFile(strReport, ForAppending, True)
Set objFolder = objFSO.GetFolder(strFolder)
For Each objChild in objFolder.SubFolders
    objReport.WriteLine objChild.Path & "," & Round(objChild.Size/intMB, 2)

Open in new window


Thanks Shift_3  To run the script do I just open a command shell and use the following?
cscript \\location of vbs file

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.