欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

获得文件夹大小的VBS代码

程序员文章站 2024-01-02 17:10:16
核心代码 '---------------------- '获得文件夹的大小 'author = baiyang 'version = 1.0 'dat...

核心代码

'----------------------
'获得文件夹的大小
'author  = baiyang
'version = 1.0
'date  = 09.08.08
'----------------------
option explicit
on error resume next
dim objfso, objlocalfolder, strarg, longlocalfoldersize, strsizemess
'判断是不是没有路径参数
if wscript.arguments.count < 1 then
  wscript.echo "参数无效, 第一个参数为路径"
  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即可。

上一篇:

下一篇: