VBSでフォルダサイズを取得
サンプルコード:
'フォルダサイズを取得
'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