Experts Exchange connects you with the people and services you need so you can get back to work.
' NAME: folderSize.vbs
' COMMENT: Scans folder sizes of a selected folder.
Dim objFSO, objFolder, objFile, objFile2, F, myVar1, myVar2, folderCount, strWrite
folderCount = 0
objFile2 = "folderdetails.csv"
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolderSrc)
'Write Header Row
Set objFile = CreateObject("Scripting.FileSystemObject")
Set strWrite = objFile.OpenTextFile(objFile2, 2, True)
strWrite.WriteLine("Folder Name,Size (MB),# Files,# Sub Folders")
Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
Set objFile2 = Nothing
Set F = Nothing
Set myVar1 = Nothing
Set myVar2 = Nothing
Set strWrite = Nothing
strWrite.WriteLine(oF.Name + "," + CStr(oF.Size /1024\1024) + "," + CStr(oF.Files.Count) + "," + CStr(oF.Subfolders.Count))
'Comment out the following line and the loop to end the statement
'to list all subfolders.(End Loop is 6 lines down)
Do While folderCount < 1
for each F in oF.Subfolders
folderCount = folderCount + 1
' browseFolder brings up the selection box to choose both the source and the destination.
Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Select a " & myVar2 & " folder:", NO_OPTIONS, "C:\Scripts")
On Error Resume Next
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
myVar1 = objPath
' objPathChk checks to make sure that a source has been selected.
If myVar1 = "" Then
MsgBox "Scan Folder Not Specified." & VbCrLf & _
"Scan will now quit.", vbOKOnly, "Terminate"
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $159.20.
Premium members get this course for $122.40.
Premium members get this course for $62.50.
Premium members get this course for $151.20.
Premium members get this course for $299.99.