<script>
//用这个函数,注意大小写,需要传入所需的目录,
function ShowFolderFileList(folderspec)
{
var fso, f, f1, fc, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.files);
s = "";
for (; !fc.atEnd(); fc.moveNext())
{
s += fc.item();
s += "<br>";
}
return(s);
}
</script>
<body>
<input type="button" value="点击" onClick="document.write(ShowFolderFileList('c:\\'));">
</body>
//用这个函数,注意大小写,需要传入所需的目录,
function ShowFolderFileList(folderspec)
{
var fso, f, f1, fc, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.files);
s = "";
for (; !fc.atEnd(); fc.moveNext())
{
s += fc.item();
s += "<br>";
}
return(s);
}
</script>
<body>
<input type="button" value="点击" onClick="document.write(ShowFolderFileList('c:\\'));">
</body>
Files 集合
一个文件夹中所有 File 对象的集合。说明
[JScript]下面这个例子说明了如何获得一个 Files 集合以及如何使用 Enumerator 对象和 for 语句来遍历该集合: [JScript]
function ShowFolderFileList(folderspec)
{
var fso, f, f1, fc, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(folderspec);
fc = new Enumerator(f.files);
s = "";
for (; !fc.atEnd(); fc.moveNext())
{
s += fc.item();
s += "<br>";
}
return(s);
}
[VBScript]下列代码说明如何获取 Files 集合,以及如何使用 For Each...Next 语句遍历该集合: [VBScript]
Function ShowFolderList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & f1.name
s = s & "<BR>"
Next
ShowFolderList = s
End Function
方法
Files 集合没有方法。