Function getDirectorySize(pCurrentDir) Dim numFSize Dim numDSize Dim strQuery Dim refItem Dim colFiles Dim colSubdirs numFSize = 0 numDSize = 0 'first get a reference to all files in the directory strQuery = "ASSOCIATORS OF {Win32_Directory='" & pCurrentDir.Name & "'} WHERE AssocClass=CIM_DirectoryContainsFile Role=GroupComponent ResultRole=PartComponent" set colFiles = refWMIService.ExecQuery(strQuery) 'loop through each file and add the size of each to numFSize For Each refItem In colFiles numFSize = numFSize + refItem.FileSize Next set colFiles = Nothing 'now get a reference to all the subdirectories strQuery = "ASSOCIATORS OF {Win32_Directory='" & pCurrentDir.Name & "'} WHERE AssocClass=Win32_SubDirectory ResultRole=PartComponent" set colSubdirs = refWMIService.ExecQuery(strQuery) 'loop through each subdirectory, and add its 'size to numDSize by recursively calling this Function For Each refItem in colSubDirs numDSize = numDSize + getDirectorySize(refItem) Next set colSubdirs = Nothing 'finally, print stats and return the total size WScript.echo pCurrentDir.Name & ": " & numFSize & " bytes in files - " & numDSize & " bytes in subdirs" getDirectorySize = numFSize + numDSize End Function