您的位置:首页 > 编程语言 > ASP

ASP实现结构化列举并查看某路径下所有文件

2005-08-26 16:29 393 查看
<!网页ASP代码,可实现结构化列举并查看某路径下所有文件,可用于动态生成网站地图,具体案例请看我的主页地图: http://freehost08.websamba.com/hzhzhz/sitemap.htm>
<!作者: 同济黄正 http://websamba.com/hzhzhz/ 应用请注明出处>
<style 此样式表须保留>
<!--
u.{background-color:FEDC76;cursor:hand;}
a{background-color:97EF53;}
font{padding-bottom:0;padding-top:0;margin-bottom:0;margin-top:0;}
-->
</style>
<title>本站文件地图</title>
<body>
<span id=shhi style="text-align:right;width:20%;position:absolute;bottom:0">
<a href=# onclick='jscript:if(rightf.style.display=="")rightf.style.display="none";else rightf.style.display="";return false' style=background-color:red>Hide/Show =></a>
</span>
<div id=rightf style="height:100%;width:80%;position:absolute;right:0;top:0">
<iframe align=right name="right" scrolling=auto style="height:100%;width:100%;" src="about:blank"> </iframe>
</div>
<base target="right">

<Script language=VBScript>
<!--

Sub window_onscroll()
rightf.style.pixelTop=document.body.scrollTop
shhi.style.top=document.body.clientHeight+document.body.scrollTop-30
End Sub

sub DoFold(index) '显示与隐藏某节点的过程
dim itm
set itm=eval("divfold" & index)
if itm.style.display="none" then
itm.style.display=""
else
itm.style.display="none"
end if
set itm = document.all(itm.sourceIndex-2)
if itm.innerText="0" then
itm.innerText="1"
else
itm.innerText="0"
end if
set itm=document.all("itmjj" & index)
if not itm is nothing then
if itm.innerText="+" then
itm.innerText="-"
else
itm.innerText="+"
end if
end if
end sub

-->
</Script>

<%
'------ASP程序段--------------------------------------
set Fso=Server.CreateObject("Scripting.FileSystemObject") '服务器须支持FSO

dim path,mappath
if request("path")="" then
path="" '须先设置好想要查看的文件夹的名称,即path=路径名称,例如要查看 http://websamba.com/hzhzhz/ 时,设置path="hzhzhz"
else
path=request("path") '可以如此设置:<a href="dirpath.asp?path=hzhzhz">..
end if
mappath=Server.MapPath("/" & path)

if Fso.folderexists(mappath)=false then
response.write "路径:http://" & Request.ServerVariables("HTTP_HOST") & "/" & path & "不存在!"
response.end
end if

dim Tf
tf=0
Sub DirThisFolder(Fo,strHead) '递归过程,程序作者: 同济黄正 http://websamba.com/hzhzhz/
if not fso.FolderExists(Fo) then exit sub
dim foN,fiN,Tt
Set Folde = Fso.GetFolder(Fo)
foN=Folde.SubFolders.count
fiN=Folde.files.count

Tt="<u lab=""包含" & foN & "个子文件夹," & fiN & "个子文件"" onclick=Dofold(" & tf & ")>"
if foN then Tt=tt & "<q id=itmjj" & tf & ">+</q>"
tt=tt & "<font face=Wingdings>0</font>" '类似图标的字符
if len(strHead) then
if fiN>0 then
Response.Write left(strHead,len(strHead)-1) & "├" & Tt & Folde.name & "</u><br>"
else
Response.Write left(strHead,len(strHead)-1) & "├" & Tt & Folde.name & "</u><br>"
end if
else
Response.Write "" & Tt & Folde.path & "</u><br>"
end if

Response.Write "<span id=divfold" & tf & " style=""display:none"">"
tf=tf +1
If foN Then
i=0
For Each Fol In Folde.SubFolders
isLastFol=(i=foN-1)
if fiN > 0 then
DirThisFolder Fol.Path,strHead & "│" '递归子文件夹
else
DirThisFolder Fol.Path,strHead & "└"
end if
i=i+1
Next
End If

If fiN > 0 Then
i=0
For Each Fi In Folde.files
'For i=0 to fiN-1
if i=fiN-1 then
Response.Write strHead & "└"
else
Response.Write strHead & "├"
end if
Response.Write "<a lab=""" & fi.size & "B " & fi.DateLastModified & """ href=""http://" _fcksavedurl="""http://"" & Request.ServerVariables("HTTP_HOST") & "/" & path & replace(fi.path,mappath,"",1) & """><font face=Wingdings>m</font>" & fso.GetFileName(fi.name) & "</a><br>"
i=i+1
Next
End If
Response.Write "</span>"
End Sub

DirThisFolder mappath,""
%>

<Script language=VBScript>
<!--
DoFold 0
-->
</Script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: