Chinaunix首页 | 论坛 | 博客
  • 博客访问: 150318
  • 博文数量: 52
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 490
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-05 12:05
文章分类

全部博文(52)

文章存档

2013年(1)

2010年(3)

2009年(6)

2008年(25)

2007年(17)

我的朋友

分类: WINDOWS

2008-05-04 14:56:00

文件: list_C_folder_size.rar
大小: 1KB
下载: 下载
'*************************************************************************
'
'Purpose: It is trival thing to find the largest folder in C: drive.
'This script will check folders sizes and sort it then show the result
'as txt to you
'
'Author: 
'
'*************************************************************************

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)    temp = 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

阅读(803) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~