使用fso获取文件夹列表
<%
function
WriteChildFolderNames(folderPath)
dim fso,
fd
set fso =
Server.CreateObject("Scripting.FileSystemObject")
set fd
= fso.GetFolder(folderPath)
Response.Write
"<br>目录 " & folderPath & "
下的子目录:<hr>"
for each item in
fd.SubFolders
Response.Write item.Name &
"<br>"
next
set fd =
nothing
set fso = nothing
end
function
'调用范例:
' 当前目录的子目录列表
WriteChildFolderNames(Server.MapPath("."))
'
通过绝对路径来引用
WriteChildFolderNames("d:\")
%>
使用fso获取文件列表
<%
function
ShowFiles(folderPath)
dim fso, fd
set fso =
Server.CreateObject("Scripting.FileSystemObject")
set fd =
fso.GetFolder(folderPath)
Response.Write "<br>文件夹
" & folderPath & " 下的文件列表:<hr>"
Response.Write "<select multiple size='10'>"
for
each f in fd.Files
Response.Write "<option>"
& f.Name & "</option><br>"
next
Response.Write "</select>"
end function
'示例:
'通过绝对路径调用:
ShowFiles("d:\")
ShowFiles("F:\downloads\mp3")
'通过相对路径调用
ShowFiles(Server.MapPath("."))
%>