获得文件夹大小的VBS代码,文件夹vbs代码
获得文件夹大小的VBS代码,文件夹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
使用方法:
将上面的挨骂保存文件为: GetFloderSize.vbs
用法: GetFloderSize.vbs C:\windows即可。
dim FileName,fs,foldername
foldername = InputBox("请输入想要在哪个文件夹查找", "VBS查找文件")
If foldername = "" Then
wscript.quit
End If
Set fs = CreateObject("scripting.filesystemobject")
digui (foldername)'调用递归函数进行查找
msgbox FileName '结果显示
'下面是递归查找函数
Function digui(path)
Set folder = fs.getfolder(path)
Set subfolders = folder.subfolders
Set Files = folder.Files
For Each i In Files
FileName=FileName & i.path & vbNewLine '找到则追加到变量FileName中
Next
For Each j In subfolders
digui (j.path) '递归查找子目录
Next
End Function
'目录列表与上述相似,稍加修改即可。
vbs代码如下:
'══代══码══开══始════
i=0
set fso=CreateObject("Scripting.FileSystemObject")
set fs=fso.getfolder(".").files
for each f in fs
i=i+1
next
msgbox "文件总数:"&i
'Coded By escortmnm from VBS团队
'══代══码══结══束════
说明:
使用folder对象下面的files属性,查到一个文件即可加1,最后输出结果。
评论关闭