这与Microsoft System Center Configuration Manager 2007有些相关,但它确实与VBScript,FileSystemObject API和读取子文件夹属性有关。
我正在尝试运行一个脚本来枚举其中一个分发点(Package Share下面的每个文件夹)上的文件夹和文件夹大小。我正在使用FileSystemObject API,使用VBscript,我可以抓取大约60%的子文件夹,并获取它们的名称和大小,但其余的返回“错误70 /权限被拒绝”。我执行脚本的帐号并不重要,我尝试在每个子文件夹对象引用之间添加Sleep()延迟。它仍然不会得到它们。
如果我手动浏览文件夹,我可以毫无问题地查看其属性。这是FSO或Windows Scripting Host的已知问题吗?我在下面附上了脚本代码。 TIA!
'****************************************************************
' Filename..: fso_subfolder_sizes.vbs
' Author....: skatterbrainz
' Date......: 02/10/2013
' Purpose...: enumerate package folders and tally disk space
'****************************************************************
Option Explicit
Const rootFolder = "\\SERVER123\ShareName$"
Dim time1, folderCount, totalSpace
Dim objFSO, objFolder, objSub
Dim GBsize, folderName, folderSIze
time1 = Timer
Set objFSO = CreateObject("Scripting.FileSystemObject")
folderCount = 0
totalSpace = 0
On Error Resume Next
Set objFolder = objFSO.GetFolder(rootFolder)
If err.Number = 0 Then
wscript.echo "<folders>"
For each objSub in objFolder.SubFolders
folderName = objSub.Name
folderSize = objSub.Size
GBsize = FormatNumber(Bytes2Gbytes(folderSize), 2) & " GB"
wscript.echo "<folder name=""" & folderName & """ size=""" & GBsize & """/>"
folderCount = folderCount + 1
totalSpace = totalSpace + folderSize
Next
Set objFolder = Nothing
wscript.echo "</folders>"
wscript.echo "--------------------------"
wscript.echo "sub-folders: " & folderCount
wscript.echo "total space: " & FormatNumber(Bytes2GBytes(totalSpace),2) & " GB"
Else
wscript.echo "root folder not found"
End If
Set objFSO = Nothing
wscript.echo "runtime: " & FormatNumber(Timer - time1, 2) & " Msecs"
Function Bytes2Gbytes(n)
If n > 0 Then
Bytes2Gbytes = (n / 1024 / 1024 / 1024)
Else
Bytes2Gbytes = 0
End If
End Function
答案 0 :(得分:1)
是的,这是一个已知问题,对于存在安全问题的文件夹(例如您的c:\ windows文件夹),当您在文件夹上使用.cize .cize时会出现错误。而是枚举每个文件并将计数和大小相加。
答案 1 :(得分:1)
尝试从共享中获取每个UserProfile的配置文件大小时遇到了同样的问题。我使用excel并使用用户名循环遍历行,我知道在共享中有个人资料,如下所示:
strUserName = ActiveCell.Value
objP = "\\SERVER\SHARE$\" & strUserName & "\UPM_Profile"
ActiveCell.Offset(0, 1).Value = (FormatNumber(objFSO.GetFolder(objP).Size, 0, , , 0) / 1024) / 1024
数千个文件夹中的一些文件夹显示“未找到路径” 当我将Share映射到driveletter时,这一切都有效:
objP = "Z:\" & strUserName '& "\UPM_Profile"
答案 2 :(得分:0)
我发现了一个有趣且可重现的行为。至少在我们的生产环境中:如果我将根路径指定为根隐藏共享(即“\ SERVER \ Share $”),它就会陷入困境。但是,如果我更深入一级,例如“\ SERVER \ Share $ \ Apps”),它似乎运行得更好。我还修改了脚本以首先打印子文件夹名称,然后查询.Size属性,这似乎指向了性能瓶颈。请注意下面更新的示例中语句排序的更改...
For each objSub in objFolder.SubFolders
folderName = objSub.Name
wscript.echo vbTab & "<folder>"
wscript.echo vbTab & vbTab & "<folderName>" & folderName & "</folderName>"
folderSize = objSub.Size
GBsize = FormatNumber(Bytes2Gbytes(folderSize), 2) & " GB"
wscript.echo vbTab & vbTab & "<folderSize>" & GBsize & "</folderSize>"
wscript.echo vbTab & "</folder>"
folderCount = folderCount + 1
totalSpace = totalSpace + folderSize
Next