'***********************************
ASP下搜索特定的文件扩展名
'***********************************
<%
function findfiles(strstartfolder,strext)
dim n,othisfolder,ofolders,ofiles,ofolder,ofile
'如果系统管理员对文件系统的权限进行细致设置话,下面的代码就要出错,但是有些目录还是可以查看的
'所以简单地把错误忽略
on error resume next
n=0
response.write("search"&strstartfolder&" ")
set othisfolder=g_fs.getfolder(strstartfolder)
set ofiles=othisfolder.files
for each ofile in ofiles
'如果是指定的文件展名,输出连接导向本身,但用不同的命令cmd
'在这里是cmd=read,即读出指定物理路径的文本文件
if issuffix(ofile.path,strext) then
response.write("
color='read'>"&ofile.path&" "
if err=0 then
n=n+1
end if
end if
next
set ofolders=othisfolder.subfolders
for each ofolder in ofolders
n=n+findfiles(ofolder.path,strext)
next
findfiles=n
end function
'***************************************************
' 下面的代码是对url后面的参数进行分析
'***************************************************
'读出各个参数的值
strcmd=ucase(request.querystring("cmd"))
strpath=request.querystring("path")
strext=request.querystring("ext")
brawdata=ucase(request.querystring("raw"))
'默认搜索.asp文件
if strpath="" then
strpath="."
end if
if strext="" then
strext=".asp"
end if
'根据不同的命令cmd执行不同的代码
select case strcmd
case "find"
response.write findfiles(strpath,strext) & "file(s) found"
case "read"
if brawdata="t" then
response.write readtextfile(strpath)
else
response.write(" "&server.htmlencode(readtextfile(strpath))&" ")
end if
case else
response.write("please specify a command to execute")
end select
'*************************************************
以上来自于<<专家门诊-ASP开发答疑>>
'************************************************* |