返回一個(gè) Drives 集合,包含了本地機(jī)器上所有可用的 Drive 對(duì)象。
object.Drives
object 應(yīng)為 FileSystemObject 。
可移動(dòng)媒體的驅(qū)動(dòng)器不需要插入媒體就可以出現(xiàn)在 Drives 集合中。
[JScript]
可以通過(guò) Enumerator 對(duì)象和 for 語(yǔ)句來(lái)逐個(gè)引用 Drives 集合中的成員:
[JScript]
function ShowDriveList()
{
var fso, s, n, e, x;
fso = new ActiveXObject("Scripting.FileSystemObject");
e = new Enumerator(fso.Drives
);
s = "";
for (; !e.atEnd(); e.moveNext())
{
x = e.item();
s = s + x.DriveLetter;
s += " - ";
if (x.DriveType == 3)
n = x.ShareName;
else if (x.IsReady)
n = x.VolumeName;
else
n = "[Drive not ready]";
s += n + "<br>";
}
return(s);
}
[VBScript]
如下列代碼所示,可以使用 For Each...Next 結(jié)構(gòu)遍歷 Drives 集合的成員:
[VBScript]
Function ShowDriveList
Dim fso, d, dc, s, n
Set fso = CreateObject("Scripting.FileSystemObject")
Set dc = fso.Drives
For Each d in dc
n = ""
s = s & d.DriveLetter & " - "
If d.DriveType = 3 Then
n = d.ShareName
ElseIf d.IsReady Then
n = d.VolumeName
End If
s = s & n & "<BR>"
Next
ShowDriveList = s
End Function
Drives 集合 | Files 屬性 | SubFolders 屬性
應(yīng)用于:FileSystemObject 對(duì)象