<%@ Language=VBScript %>
<%
function bianli(path)
dim fso 'fso对象
dim objFolder '文件夹对象
dim objSubFolders '子文件夹集合
dim objSubFolder '子文件夹对象
dim objFiles '文件集合
dim objFile '文件对象
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 "<br>---"
Response.Write objFile.name
next
Response.Write "<p>"
bianli(nowpath) '调用递归
next
set objFolder=nothing
set objSubFolders=nothing
set fso=nothing
end function
%>
<%
bianli("d:") '调用bianli()函数,这里是遍历d:盘
%>
<%
'创建一个FileSystemObject对象的事例
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
'创建一个Folder对象
Set MyFolder=MyFileObject.GetFolder("c:\MyFolder")
'循环显示其中子目录
For Each thing in MyFolder.Files
Response.Write("<p>"&thing)
Next
%>
<HTML>
<HEAD><TITLE>文件是否存在示例</TITLE></HEAD>
<BODY>
<%
MySelf=Request.ServerVariables("PATH_TRANSLATED")
'创建一个FileSystemObject对象事例
Set MyFileObject=Server.CreateObject("Scripting.FileSystemObject")
IF MyFileObject.FileExists("MySelf")
Response.write("存在这个文件")
Else
Response.write("不存在这个文件")
END IF
%>
</BODY>
</HTML>