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>
<!作者: 同济黄正 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>
相关文章推荐
- ASP实现结构化列举并查看某路径下所有文件
- JAVA---实现检索指定路径下的所有的下属文件夹和文件
- python实现批量删除某个路径下所有的某种文件
- VS 2008 VC 实现 --- 遍历一个文件夹下的所有文件(即查看文件名,不包含子目录)
- 用Asp隐藏文件路径实现防盗链
- 用Asp隐藏文件路径实现防盗链
- 用Asp隐藏文件路径实现防盗链
- 在linux下用C语言实现递归查看某个目录中的所有文件
- js如何给页面中所有的img对象加上onclick事件,且实现在新窗体中查看该图片文件
- 用Asp隐藏文件路径,实现防盗链
- asp.net实现上传文件显示本地绝对路径的实例代码
- iOS小技巧 - 获取指定文件夹下的所有相对路径(包括子文件夹路径),并实现指定文件夹下的所有文件的全部移动
- ASP.NET 2.0实现类似QQ邮箱中‘HTML方式查看’功能查看Office文件
- 用Asp隐藏文件路径实现防盗链
- 用Asp隐藏文件路径,实现防盗链
- asp.net中用FileStream类实现下载文件功能,自定义下载路径,像IE下载一样
- 用递归算法实现ASP程序用fso对硬盘上某个路径下目录和文件的遍历
- 实现防盗链,用Asp隐藏文件路径
- Asp.net 获取指定目录下的后缀名为".doc" 的所有文件名和文件路径