<html><body style="font-size: 13px">
读取一个文件夹或子文件夹内的所有文件范例<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 对象实例内存空间
%>
</body></html> 作者:
xuyaoairen 时间: 2006-5-10 16:37
<%@ Language=VBScript %>
<%
'我写的一个遍历目录以及目录下文件的函数,
%>
<%
function bianli(path)
set fso=server.CreateObject("scripting.filesystemobject")
on error resume next
set objFolder=fso.GetFolder(path)
set objSubFolders=objFolder.Subfolders
for each objSubFolder in objSubFolders
nowpath=path + "\" + objSubFolder.name
Response.Write nowpath
set objFiles=objSubFolder.Files
for each objFile in objFiles
Response.Write "
---"
Response.Write objFile.name
next
Response.Write "<p>"
bianli(nowpath)'递归
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function
%>
<%
bianli("d:") '遍历d:盘
%>