分类: WINDOWS
2008-05-04 14:56:00
|
Dim folderspecs(10000,1) 'space to store information
Dim intintCounter
Dim strTmpdir,strBox1,strBox2
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("wscript.Shell")
intCounter = 0 'reset intCounter and define as global variable
Set drive = fso.GetDrive("C:\") 'check c: drive only
strTmpdir = fso.GetSpecialFolder(2) 'record file location
strBox1 = Wshshell.Popup ("Checking folders' size on C: drive,please wait for minutes!",10, "", vbOKOnly)
'call CheckFoler
CheckFolder(drive.RootFolder) 'sort result, larger folders first
strBox2 = Wshshell.Popup ("Sorting results.....wait please!", 10, "", vbOKOnly)
'call SortInfo
SortInfo
output = strTmpdir & "\list.txt"
set outputfile = fso.CreateTextFile(output, true)
for x=0 to intCounter-1
size = FormatNumber(folderspecs(x, 0)/1024^2,1)
size = right(space(30) & size, 10) & " MB"& space(5)
outputfile.WriteLine size & folderspecs(x,1)
next
outputfile.close
set wshshell = CreateObject("WScript.Shell")
wshshell.run output 'launch report file:
sub CheckFolder(folderobj) 'determine folder size
on error resume next 'important: always turn off error handling!
size = folderobj.size 'check for access violation errors
if not err.Number=0 then
size=-1
Err.clear
End if
On error goto 0 'turn error handling back on:
folderspecs(intCounter,0) = size 'add entry:
folderspecs(intCounter,1) = folderobj.path
intCounter = intCounter + 1 'check all subfolders,this is the basis of recursive calling'
On error resume Next 'Always turn off error handling is important!
For each subfolder in folderobj.subfolders
'to handle access violation errors:
'check each subfolder individually
'by calling myself
CheckFolder subfolder
Next
Err.Clear 'turn error handling back on:
On error goto 0
end Sub
Sub SortInfo
For x = 0 to intCounter-1
For y = x+1 to intCounter-2
If folderspecs(x,0)
folderspecs(x,0)=folderspecs(y,0)
folderspecs(y,0)=temp
temp = folderspecs(x,1)
folderspecs(x,1)=folderspecs(y,1)
folderspecs(y,1)=temp
End if
Next
next
end sub