首页 > 编程 > VBScript > 正文

获得文件夹大小的VBS代码

2020-07-26 11:47:17
字体:
来源:转载
供稿:网友

核心代码

'----------------------'获得文件夹的大小'Author  = baiyang'Version = 1.0'Date  = 09.08.08'----------------------Option ExplicitOn Error Resume NextDim objFSO, objLocalFolder, strArg, longLocalFolderSize, strSizeMess'判断是不是没有路径参数If WScript.Arguments.Count < 1 Then  WScript.Echo "参数无效, 第一个参数为路径"  WScript.QuitElse  strArg = WScript.Arguments(0)End IfSet objFSO = CreateObject("Scripting.FileSystemObject")Set objLocalFolder = objFSO.GetFolder(strArg)If objLocalFolder = Empty Then  WScript.Echo "Invalid Path"  WScript.QuitEnd IflongLocalFolderSize = objLocalFolder.SizeIf 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 IfWScript.Echo strSizeMessSet objFSO = NothingSet objLocalFolder = NothingWScript.Quit

使用方法:

将上面的挨骂保存文件为: GetFloderSize.vbs
用法: GetFloderSize.vbs C:/windows即可。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表