请问怎么遍历一个文件夹里的文件,并把文件名读取出来
---------------------------------------------------------------
1<html><body style="font-size: 13px">
2读取一个文件夹或子文件夹内的所有文件范例<br/><br/>
Dim objFSO,objFolder,objFile,FF '声明 objFSO 变量存放对象实例
FF = Server.MapPath("./images")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(ff) Then
Response.write "文件夹 "&ff&" 里所有的文件:<br/>"
Set objFolder = objFSO.GetFolder(ff)
For Each objFile in objFolder.Files
Response.Write objFile.Name & "<br/>"
Next
Else
Response.Write "文件夹"&ff&"不存在,无法读取相关信息!"
End If
Set objFolder = Nothing
Set objFSO = Nothing '释放 FileSystemObject 对象实例内存空间
1</body></html>
---------------------------------------------------------------
1@ Language=VBScript
1
2'我写的一个遍历目录以及目录下文件的函数,
1
2function bianli(path)
3set fso=server.CreateObject("scripting.filesystemobject")
4
5on error resume next
6set objFolder=fso.GetFolder(path)
7
8set objSubFolders=objFolder.Subfolders
9
10for each objSubFolder in objSubFolders
11
12nowpath=path + "\" + objSubFolder.name
13
14Response.Write nowpath
15
16set objFiles=objSubFolder.Files
17
18for each objFile in objFiles
19Response.Write "
20\---"
21Response.Write objFile.name
22next
23Response.Write "
<p>"
bianli(nowpath)'递归
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function
bianli("d:") '遍历d:盘