问题描述
这在某种程度上与Microsoft System Center Configuration Manager 2007有关,但实际上与VBScript,FileSystemObject API和读取子文件夹属性有关.
This is somewhat related to Microsoft System Center Configuration Manager 2007, but it's really about an issue with VBScript, the FileSystemObject API and reading sub-folder properties.
我正在尝试运行一个脚本来枚举我们的分发点(软件包共享"下的每个文件夹)上的文件夹和文件夹大小.我使用带有VBscript的FileSystemObject API,我可以抓取大约60%的子文件夹,并获取它们的名称和大小,但是其余的返回错误70/权限被拒绝".不管以哪个帐户执行脚本都无所谓,并且我尝试在每个子文件夹对象引用之间添加Sleep()延迟.仍然无法全部解决.
I am trying to run a script to enumerate the folders and folder sizes on one of our Distribution Points (every folder beneath the Package Share). I'm using the FileSystemObject API, with VBscript, I can crawl about 60% of the sub-folders, and get their names and sizes, but then the rest return "error 70 / Permission Denied". It doesn't matter what account I execute the script as, and I've tried adding a Sleep() delay between each sub-folder object reference. It still won't get them all.
如果我手动浏览文件夹,则可以毫无问题地查看它们的属性.这是FSO还是Windows Scripting Host的已知问题?我已在下面附加了脚本代码. TIA!
If I manually explore the folders, I can view their properties without any problem. Is this a known issue with FSO or maybe Windows Scripting Host? I've attached the script code below. 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
推荐答案
尝试从共享中获取每个UserProfile的配置文件大小时,我遇到了相同的问题.我使用了excel,并使用我知道共享中有个人资料的用户名遍历行,如下所示:
I had the same problem when trying to get profile size of each UserProfile from a share. I used excel and was looping through rows with usernames that I knew had a profile in the share, like this:
strUserName = ActiveCell.Value
objP = "\\SERVER\SHARE$\" & strUserName & "\UPM_Profile"
ActiveCell.Offset(0, 1).Value = (FormatNumber(objFSO.GetFolder(objP).Size, 0, , , 0) / 1024) / 1024
成千上万个文件夹中只有一部分提供了找不到路径"当我改为将共享映射到驱动器号时,一切都成功了:
Just some of the thousands folders gave "Path Not Found"It all worked when I instead mapped the Share to a driveletter:
objP = "Z:\" & strUserName '& "\UPM_Profile"
这篇关于用VBscript枚举子文件夹属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!