标题: 请教各位前辈VBS中drives集合的count属性和ITEM属性的实际应用 [打印本页] 作者: SUPERWOMEN 时间: 2009-6-30 18:38 标题: 请教各位前辈VBS中drives集合的count属性和ITEM属性的实际应用 想请问各位前辈drives集合的count属性和ITEM属性的实际应用。麻烦看下下面函数:
Function ShowDriveList()
Dim fso, d, dc, s, n
Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives msgbox dc.count
For Each d in dc
n = ""
s = s & d.DriveLetter & " - "
If d.DriveType = Remote Then
n = d.ShareName
ElseIf d.IsReady Then
n = d.VolumeName
End If
s = s & n &"<BR>"
Next
ShowDriveList = s
End Function
call ShowDriveList()
msgbox ShowDriveList
1)我的电脑上有4个盘,执行时msgbox dc.count,弹出两次对话框,都显示的是4,请教前辈们为什么会出现两次?
2)ITEM属性在我这段代码中怎么应用?
请大侠们给指点下。谢谢。作者: fei.ge 时间: 2009-6-30 19:23
这是QTP帮助文档上的内容.
请问楼上的前辈,msgbox dc.Item("C:").VolumeName 这句应该放到那个位置,我执行了下,弹出框中没有任何内容,不知道这句话放的地方对不?
另:
msgbox dc.Item("C:").VolumeName中"C:"可以用于变量表示么?
还请前辈给与详细指点。
谢谢。作者: SUPERWOMEN 时间: 2009-7-1 13:54
感谢楼上这位前辈的思路。
我前辈的思路加到代码中,最终终于调试通过了。供大家参考。如有不对地方,请大家都得指点。
Function ShowDriveList()
Dim fso, d, dc, s, n
Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives
msgbox dc.count
For Each d in dc
n = ""
s = s & d.DriveLetter & " - "
If d.DriveType = Remote Then
n = d.ShareName
ElseIf d.IsReady Then
n = d.VolumeName
End If
s = s & n &"<BR>"
If d.IsReady Then msgbox d.DriveLetter&"可用空间"&dc.Item(d.DriveLetter).FreeSpace Else
msgbox d.DriveLetter&"驱动器未就绪"
End If
Next
ShowDriveList = s
End Function
msgbox ShowDriveList