如何读取指定文件夹中的所有文件的文件名??

--------------只读指定目录中的文件

1<html>
2<head><title>文件夹内容</title></head>
3<body>   

'创建一个FileSystemObject对象的事例
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
'创建一个Folder对象
Set MyFolder=MyFileObject.GetFolder("c:\MyFolder")
'循环显示其中文件
For Each thing in MyFolder.Files
Response.Write("<p>"&amp;thing)
Next

1</p></body>
2</html>

---------------------------------完善的函数

 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 "---"   
20Response.Write objFile.name   
21next   
22Response.Write "

<p>"
bianli(nowpath)'递归

next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function

bianli("d:") '遍历d:盘

Published At
Categories with Web编程
comments powered by Disqus