▼ JScript のダウンロード
▼ VBScript のダウンロード
System Volume Information は、無駄に使われてる場合が多いそうです。( 今日 5G 削除しました )
参考ページ
show-folders-size.js
001.
// ************************************************
002.
// カンマ編集
003.
// ************************************************
004.
String.prototype.number_format =
005.
function
(prefix) {
006.
var
num =
this
.valueOf();
007.
prefix = prefix ||
''
;
008.
num +=
''
;
009.
var
splitStr = num.split(
'.'
);
010.
var
splitLeft = splitStr[0];
011.
var
splitRight = splitStr.length > 1 ?
'.'
+ splitStr[1] :
''
;
012.
var
regx = /(\d+)(\d{3})/;
013.
while
(regx.test(splitLeft)) {
014.
splitLeft = splitLeft.replace(regx,
'$1'
+
','
+
'$2'
);
015.
}
016.
return
prefix + splitLeft + splitRight;
017.
}
018.
019.
// ************************************************
020.
// オブジェクト
021.
// ************************************************
022.
var
Shell =
new
ActiveXObject(
"Shell.Application"
);
023.
var
WshShell =
new
ActiveXObject(
"WScript.Shell"
);
024.
var
Fso =
new
ActiveXObject(
"Scripting.FileSystemObject"
);
025.
026.
// ************************************************
027.
// 管理者権限のコマンドプロンプトで再実行
028.
// ************************************************
029.
if
( WScript.Arguments.length == 0 ) {
030.
Shell.ShellExecute(
"cmd.exe"
,
"/c cscript.exe "
+ Dd(WScript.ScriptFullName) +
" next"
+
" & pause"
,
""
,
"runas"
, 1 );
031.
WScript.Quit();
032.
}
033.
034.
035.
var
target = SelectDir(
"対象フォルダを選択して下さい"
)
036.
if
( target ==
""
) {
037.
WScript.Quit();
038.
}
039.
040.
WScript.Echo( target )
041.
042.
// ************************************************
043.
// フォルダオブジェクト取得
044.
// ************************************************
045.
var
objFolder = Fso.GetFolder(target)
046.
047.
var
folderCollection =
new
Enumerator(objFolder.SubFolders);
048.
049.
var
TargetSize = 0;
050.
var
obj;
051.
var
num;
052.
var
line;
053.
for
( ;!folderCollection.atEnd(); folderCollection.moveNext()) {
054.
055.
obj = folderCollection.item();
056.
057.
try
{
058.
num = Math.floor(obj.Size / 1024) / 1024;
059.
num = Math.floor( num * 1000 ) / 1000
060.
line = Lpad((
""
+ num).number_format(),
" "
, 15) +
" M : "
+ obj.Name
061.
WScript.Echo( line );
062.
063.
// フォルダ全体の合計
064.
TargetSize = TargetSize + obj.Size
065.
}
066.
catch
(e) {
067.
WScript.Echo( obj.Name +
" : 処理できません"
);
068.
}
069.
070.
}
071.
072.
WScript.Echo(
""
);
073.
074.
num = Math.floor(TargetSize / 1024) / 1024;
075.
num = Math.floor( num * 1000 ) / 1000
076.
line = Lpad((
""
+ num).number_format(),
" "
, 15) +
" M : "
+
"表示合計"
077.
WScript.Echo( line );
078.
079.
// ************************************************
080.
// ディレクトリ選択
081.
// ************************************************
082.
function
SelectDir( strTitle ) {
083.
084.
var
obj
085.
086.
obj = Shell.BrowseForFolder( 0, strTitle, 0x4B, 0 )
087.
if
( obj ==
null
) {
088.
return
""
;
089.
}
090.
if
( !obj.Self.IsFileSystem ) {
091.
ErrorMessage =
"ファイルシステムではありません"
;
092.
return
""
;
093.
}
094.
095.
return
obj.Self.Path;
096.
097.
}
098.
099.
// ************************************************
100.
// ダブルクォートで囲む
101.
// ************************************************
102.
function
Dd( strValue ) {
103.
104.
return
"\""
+ strValue +
"\""
105.
106.
}
107.
108.
// ************************************************
109.
// 指定数、指定文字列左側を埋める
110.
// ※少数以下3桁の調整
111.
// ************************************************
112.
function
Lpad( strValue, str, nLen ) {
113.
114.
var
i;
115.
var
wk =
""
;
116.
117.
for
( i = 0; i < nLen; i++ ) {
118.
wk += str;
119.
}
120.
121.
var
test = strValue.split(
"."
);
122.
if
( test.length == 2 ) {
123.
if
( test[1].length == 0 ) {
124.
strValue +=
"000"
125.
}
126.
if
( test[1].length == 1 ) {
127.
strValue +=
"00"
128.
}
129.
if
( test[1].length == 2 ) {
130.
strValue +=
"0"
131.
}
132.
}
133.
else
{
134.
strValue +=
".000"
135.
}
136.
137.
return
( wk + strValue ).slice( nLen * -1 );
138.
139.
}
show-folders-size.vbs
001.
' ************************************************
002.
' 管理者権限で実行用
003.
' ************************************************
004.
Set
Shell = CreateObject(
"Shell.Application"
)
005.
006.
' ************************************************
007.
' 管理者権限で再実行
008.
' ************************************************
009.
if Wscript.Arguments.Count = 0 then
010.
Shell.ShellExecute
"cmd.exe"
,
"/c cscript.exe "
& Dd(WScript.ScriptFullName) &
" next"
&
" & pause"
,
""
,
"runas"
, 1
011.
Wscript.Quit
012.
end if
013.
014.
' ************************************************
015.
' 除外フォルダ名を スペースで区切って並べる
016.
' (簡易的な除外)
017.
' ************************************************
018.
Dim
Exclude
019.
Exclude =
".gem"
020.
Exclude = Lcase(Exclude)
021.
022.
' ************************************************
023.
' 処理用
024.
' ************************************************
025.
Set
WshShell = CreateObject(
"WScript.Shell"
)
026.
Set
Fso = CreateObject(
"Scripting.FileSystemObject"
)
027.
028.
Dim
target
029.
030.
' ************************************************
031.
' 対象フォルダを選択
032.
' ************************************************
033.
target = SelectDir(
"対象フォルダを選択して下さい"
)
034.
if target =
""
then
035.
Wscript.Quit
036.
end if
037.
038.
Wscript.Echo target
039.
Wscript.Echo
040.
041.
' ************************************************
042.
' フォルダオブジェクト取得
043.
' ************************************************
044.
Set
objFolder = Fso.GetFolder(target)
045.
046.
' ************************************************
047.
' サブフォルダコレクション取得
048.
' ************************************************
049.
Set
colSubFolder = objFolder.SubFolders
050.
051.
' ************************************************
052.
' 一覧
053.
' ************************************************
054.
Dim
TargetSize : TargetSize = 0
055.
For
Each
obj in colSubFolder
056.
057.
Do
While
true
058.
059.
if InStr(Exclude,Lcase(obj.Name)) > 0 then
060.
Exit
Do
061.
end if
062.
063.
on error resume next
064.
Wscript.Echo Lpad(FormatNumber((Fix(obj.Size / 1024) / 1024),3),
" "
, 15) &
" M : "
& obj.Name
065.
if Err.Number <> 0 then
066.
Wscript.Echo
" ( "
& obj.Name &
" : 処理できません )"
067.
else
068.
TargetSize = TargetSize + obj.Size
069.
end if
070.
on error goto 0
071.
072.
073.
Exit
Do
074.
Loop
075.
076.
077.
Next
078.
079.
Wscript.Echo
080.
081.
Dim
AllSize
082.
Dim
er : er = 0
083.
on error resume next
084.
AllSize = objFolder.Size
085.
if Err.Number <> 0 then
086.
er = 1
087.
AllSize = TargetSize
088.
end if
089.
on error goto 0
090.
091.
092.
Wscript.Echo Lpad(FormatNumber((Fix(TargetSize / 1024) / 1024),3),
" "
, 15) &
" M : "
&
"表示合計"
093.
094.
if er = 1 then
095.
Wscript.Echo
" ( "
& target &
" のサイズは取得できませんでした )"
096.
else
097.
Wscript.Echo Lpad(FormatNumber((Fix(AllSize / 1024) / 1024),3),
" "
, 15) &
" M : "
& target &
" のサイズ"
098.
end if
099.
100.
Dim
fsize : fsize = 0
101.
For
Each
file in objFolder.files
102.
fsize = fsize + file.size
103.
Next
104.
Wscript.Echo Lpad(FormatNumber((Fix((fsize) / 1024) / 1024),3),
" "
, 15) &
" M : "
& target &
" 下のファイル"
105.
106.
Wscript.Echo
107.
108.
' ************************************************
109.
' ディレクトリ選択
110.
' ************************************************
111.
Function
SelectDir( strTitle )
112.
113.
Dim
obj
114.
115.
Set
obj = Shell.BrowseForFolder( 0, strTitle, &H4B, 0 )
116.
if obj is nothing then
117.
SelectDir =
""
118.
Exit
Function
119.
end if
120.
if not obj.Self.IsFileSystem then
121.
ErrorMessage =
"ファイルシステムではありません"
122.
SelectDir =
""
123.
Exit
Function
124.
end if
125.
126.
SelectDir = obj.Self.Path
127.
128.
End
Function
129.
130.
' ************************************************
131.
' ダブルクォートで囲む
132.
' ************************************************
133.
Function
Dd( strValue )
134.
135.
Dd =
""
""
& strValue &
""
""
136.
137.
End
function
138.
139.
' ************************************************
140.
' 指定数、指定文字列左側を埋める
141.
' ************************************************
142.
Function
Lpad( strValue, str, nLen )
143.
144.
Lpad = Right(
String
(nLen,str) & strValue, nLen )
145.
146.
End
Function