Search This Blog

Saturday, September 21, 2013

How to get Windows Folder sizes recursively

Ever need to know the folder sizes that has several sub-folders, windows explorer takes really long time and requires checking properties of each folder.


This script will do the job just need excel installed on your machine


Creates a clean excel sheet



‘ PLEASE NOTE THAT YOU WOULD NEED EXCEL INSTALLED ON YOUR MACHINE


Dim oFS, oFolder

Dim objexcel, r, lnameArray, lname, nameLength

set oFS = WScript.CreateObject(“Scripting.FileSystemObject”)

set oFolder = oFS.GetFolder(“D:\GE”)

Set objExcel = createobject(“Excel.application”)

objexcel.Workbooks.add

objexcel.Cells(1, 1).Value = “Folder Path”

objexcel.Cells(1, 2).Value = “Folder Name”

objexcel.Cells(1, 3).Value = “Size (MB)”

objexcel.Cells(1, 4).Value = “# Files”

objexcel.Cells(1, 5).Value = “# Sub Folders”

objexcel.Visible = True

Wscript.Sleep 300

r=2


ShowFolderDetails oFolder, r


‘    objexcel.ActiveWorkbook.SaveAs(“LogonReport.xls”)

‘    objexcel.Quit

MsgBox “Done”


Function ShowFolderDetails(oF,r)

Dim F

objexcel.Cells(r, 1).Value = oF.Path

objexcel.Cells(r, 2).Value = oF.Name

objexcel.Cells(r, 3).Value = oF.Size /1024\1024

objexcel.Cells(r, 4).Value =  oF.Files.Count

objexcel.Cells(r, 5).Value =  oF.Subfolders.count

r = r+1

for each F in oF.subfolders

ShowFolderDetails F, r

next

End Function




How to get Windows Folder sizes recursively

No comments:

Post a Comment