这与 Microsoft System Center Configuration Manager 2007 有点相关,但实际上与 VBScript、FileSystemObject API 和读取子文件夹属性有关。
我正在尝试运行一个脚本来枚举我们的一个分发点(包共享下的每个文件夹)上的文件夹和文件夹大小。我正在使用带有 VBscript 的 FileSystemObject API,我可以抓取大约 60% 的子文件夹,并获取它们的名称和大小,但其余的返回“错误 70 / Permission Denied”。我以什么帐户执行脚本并不重要,我尝试在每个子文件夹对象引用之间添加一个 Sleep() 延迟。它仍然不会得到他们所有。
如果我手动浏览这些文件夹,我可以毫无问题地查看它们的属性。这是 FSO 还是 Windows 脚本主机的已知问题?我在下面附上了脚本代码。蒂亚!
'****************************************************************
' 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