欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

列出指定目录下的所有文件和目录

程序员文章站 2022-06-05 12:24:52
<%@ language = vbscript %> <%server.scripttimeout=5000%> &...
<%@ language = vbscript %>
<%server.scripttimeout=5000%>
<html>

<head>
<style type="text/css">
/* outline style sheet */
ul ul {display: none;
margin-left: 20pt}
</style>
<script language="javascript">
function checkparent(src, dest) {
// search for a specific parent of the current element
while (src!=null) {
if (src.tagname == dest) return src;
src = src.parentelement;
}
return null;
}
function outline() {
// expand or collapse if a list item is clicked.
var open = event.srcelement;
// make sure clicked inside an li. this test allows rich html inside lists.
var el = checkparent(open, "li");
if (null!=el) {
var pos = 0;
// search for a nested list
for (var pos=0; pos<el.children.length; pos++) {
if ("ul"==el.children[pos].tagname) break;
}
if (pos==el.children.length) return;
} else return;
el = el.children[pos];
if ("ul"==el.tagname) {
// expand or collapse nested list
if (""==el.style.display) {
el.style.display = "block";
el.style.liststyleimage = "url(images/folder.gif)";
el.parentelement.style.liststyleimage = "url(images/ofolder.gif)";
}
else
{
el.style.display = "";
el.parentelement.style.liststyleimage = "url(images/folder.gif)";
}
}
event.cancelbubble = true;
}
document.onclick = outline;
</script>

<base target="main">
<title>folders</title>
<link rel="stylesheet" type="text/css" href="ase.css">
</head>

<body topmargin="0" leftmargin="0">

<script language=vbscript runat = server>
dim fs, folderpara, folderarray
set fs = createobject("scripting.filesystemobject")
if not isempty(request("txtrelative")) then
folderpara=server.mappath(request("txtrelative"))
else
folderpara=request("txtabsolute")
end if
response.write "<ul>"
response.write "<li style='list-style-image: url(images/folder.gif)'><a href='files.asp?spath=" &
folderpara & "'>" & folderpara & "</a></li>"
call showfolderlist(folderpara)
response.write "</ul>"
set fs = nothing

sub showfolderlist(folderspec)
dim f, f1, fc, s,fs
set fs=server.createobject("scripting.filesystemobject")
set f = fs.getfolder(folderspec)
set fc = f.subfolders
set fs=f.files
'if (not (fc.count = 0)) then
response.write "<ul>"
for each f1 in fc
s = f1.name
if (not ((left (s, 1)) = "_")) then
response.write "<li>"
response.write "<a href='files.asp?spath=" & f1 & "'>"
response.write s & "</li>"
response.write "</a>"
call showfolderlist((folderspec & "/" & s))
end if
next

for each f1 in fs
s = f1.name
if (not ((left (s, 1)) = "_")) then
response.write "<li>"
response.write "<a href='files.asp?spath=" & f1 & "'><font color=666666>"
if instr(s,"product")>0 then
response.write replace(s,"product","<font color=008800>product</font>")
else
if instr(s,"prod")>0 then
response.write replace(s,"prod","<font color=008800>prod</font>")
else
response.write s
end if
end if
response.write "</font></li>"
response.write "</a>"
end if
next
response.write "</ul>"
'end if
end sub
</script>

</body>
</html>