Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Disk for Directory Sizes

Status
Not open for further replies.

djtech2k

MIS
Jul 24, 2003
1,097
US
I need something that I can use to search through a disk and find directories that are over a certain size. For example, I would like something to search a machine and return a list of any directories that have a total size of over 500mb.

I know it will be something with filesystemobject, am not sure how I can get it to run through an entire disk and not just one directory.
 
Ok, I think I have the recursion of the folders working, now how do I get the directory size in something like kb or mb?
 
Nevermind my last post. I have the size in bytes now. I just need to convert.
 
I have got everything working now, but have a simple question. When I dump the info I want in a delimited format or to an xls, how can I order the results? What I mean is that if I export say the directory path and the size, how can I sort them with the larger sizes at the top?

As of now, I dump, then manually open excel and import/format the data. If I can sort/format it programatically, that would be great.
 
I'm not great with excel, but the following worked for me.

Code:
Option Explicit

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const OutputFile = "C:\temp\dir.csv"
Const xlAscending = 1
Const xlDescending = 2
Const xlNo = 2
Const xlYes = 1

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder : Set objFolder = objFSO.GetFolder("C:\temp")
Dim objFile : Set objFile = objFSO.OpenTextFile(OutputFile, ForWriting, True)
Dim objSubFolder
For Each objSubFolder In objFolder.SubFolders
	objFile.WriteLine objSubFolder.Name & "," & FormatNumber(objSubFolder.Size/1024^2, 2)
Next
objFile.Close

Dim objExcel : Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Open OutputFile
Dim objWorkbook : Set objWorkbook = objExcel.Worksheets(1)
Dim objRange : Set objRange = objWorkbook.Range("B1")
objRange.Sort objRange,xlDescending,,,,,,xlNo

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Have a look here:
faq329-3362
Furthermore you may use the CopyFromRecordset method of the Excel.Range object.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top