這篇文章主要介紹了vbs中獲得文件夾大小的代碼,需要的朋友可以參考下
代碼如下:
'----------------------
'獲得文件夾的大小
'author = baiyang
'version = 1.0
'date = 09.08.08
'----------------------
option explicit
on error resume next
dim objfso, objlocalfolder, strarg, longlocalfoldersize, strsizemess
'判斷是不是沒有路徑參數(shù)
if wscript.arguments.count < 1 then
wscript.echo 參數(shù)無效, 第一個(gè)參數(shù)為路徑
wscript.quit
else
strarg = wscript.arguments(0)
end if
set objfso = createobject(scripting.filesystemobject)
set objlocalfolder = objfso.getfolder(strarg)
if objlocalfolder = empty then
wscript.echo invalid path
wscript.quit
end if
longlocalfoldersize = objlocalfolder.size
if longlocalfoldersize>=1024 and longlocalfoldersize<1024*1024 then
strsizemess = round( longlocalfoldersize/1024, 3 ) & k
elseif longlocalfoldersize>=1024*1024 and longlocalfoldersize<1024*1024*1024 then
strsizemess = round( longlocalfoldersize/1024/1024, 3 ) & m
elseif longlocalfoldersize>=1024*1024*1024 then
strsizemess = round( longlocalfoldersize/1024/1024/1024, 3 ) & g
else
strsizemess = longlocalfoldersize & b
end if
wscript.echo strsizemess
set objfso = nothing
set objlocalfolder = nothing
wscript.quit
使用方法:
將上面的挨罵保存文件為: getflodersize.vbs
用法: getflodersize.vbs c:\windows即可。