急!请教使用FSO显示xxx.*文件,在线等,马上结分

X_Saint 2005-12-24 03:07:57
请教如何使用FSO显示指定目录下的所有指定类型的文件
谢谢


Dec 24 PM 6 前结分
...全文
139 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
tylchina 2005-12-24
  • 打赏
  • 举报
回复
学习
竹林听雨2005 2005-12-24
  • 打赏
  • 举报
回复
学习,更佩服楼主。
wangyingdong 2005-12-24
  • 打赏
  • 举报
回复
<%
'==================================================
'函数名:fso
'作 用:Fso组件
'参 数:无
'==================================================
function fso(filename)
set fs=server.CreateObject ("scripting.filesystemobject")
set fsts=fs.opentextfile(server.mappath(filename),1)
body=fsts.readall
fso=body
end function
%>



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="expires" content="0">
<title>上传文件浏览</title>
</head>

<body style='MARGIN: 0px'>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="1" style="border-collapse: collapse; border: 1px solid #666666;"> <tr align="center" bgcolor="#6D89DD">
<td height="20" class="tdtitle">图 片 浏 览</td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="475" valign="top"><table width="95%" border="0" align="center" cellpadding="3" cellspacing="3">
<%
maxpage=25
FileCount=0
if request("page")<>"" then
curPage=cint(request("page"))
else
curPage=1
end if

listtype=request("listtype")
inputname=request("inputname")
select case listtype
case "pic"
strUpFileType="jpg|gif|bmp|png"
case "flash"
strUpFileType="swf"
case "media"
strUpFileType="wmv|asf|avi|mpg|ram|rm|ra"
case else
strUpFileType="all"
end select
n=1
foldername=request.QueryString("foldername")
url=Request.ServerVariables("SCRIPT_NAME")&"?listtype="&listtype&"&foldername="&foldername&"&"
if foldername=Empty then
foldernames=Server.MapPath("../"&webuppath)
else
foldernames=Server.MapPath("../"&webuppath&foldername)
end if
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(foldernames)
for each theFolder in folder.SubFolders
if n=1 then response.write "<tr align=center>" & vbcrlf
'if FileCount mod 5=0 then response.write "<tr align=center>" & vbcrlf
response.write "<td><a href=?listtype="&listtype&"&inputname="&inputname&"&foldername="&theFolder.Name&"><img src=../images/folder.gif width=100 height=70 border=0 align=absmiddleon alt='文件夹大小:"&format(theFolder.Size)&"<br>修改时间:"&theFolder.DateLastModified&"'></a><br>"&theFolder.Name&"</td>" & vbcrlf
if n=5 then n=0:response.write "</tr>" & vbcrlf
n=n+1
next
For Each theFile In folder.Files
strFileType=lcase(mid(theFile.Name,instrrev(theFile.Name,".")+1))
if instr(strUpFileType,strFileType)>0 then
FileCount=FileCount+1
'TotalSize=TotalSize+theFile.Size
end if
next
total=FileCount
FileCount=0
if curpage<1 then
curpage=1
end if
if (curpage-1)*MaxPage>total then
if (total mod MaxPage)=0 then
curpage= total \ MaxPage
else
curpage= total \ MaxPage + 1
end if
end if
For Each theFile In folder.Files
c=c+1
if FileCount=maxpage then exit for
if c>MaxPage*(CurPage-1) then
'if n=1 then response.write "<tr align=center>" & vbcrlf
if FileCount mod 5=0 then response.write "<tr align=center>" & vbcrlf
strFileType=lcase(mid(theFile.Name,instrrev(theFile.Name,".")+1))
if instr(strUpFileType,strFileType)>0 then
call list()
FileCount=FileCount+1
else
call list()
FileCount=FileCount+1
end if
if n=5 then n=0':response.write "</tr>" & vbcrlf
n=n+1
'FileCount=FileCount+1
if FileCount mod 5=0 then response.write "</tr>" & vbcrlf
end if
Next
set fso=nothing
%>
</table></td>
</tr>
<tr>
<td height="20" align="center"><a href=<%=Request.ServerVariables("SCRIPT_NAME")%>?listtype=<%=listtype%>&foldername=>返回</a> <%showpage url,total,maxpage,curpage%></td>
</tr>
</table>
<%
Function format(fig)
If fig <1024 Then
format = fig&" B"
ElseIf fig < 1048576 Then
format = Round(fig / 1024.1) & " KB"
Else
format = Round((fig/1024)/1024.1) & " MB"
End If
End Function
sub list()
select case strFileType
case "jpg","gif","bmp","png"
response.write "<td><img src='../" &webuppath&foldername&"/"&theFile.Name& "' border='0' title='文件大小:"&format(theFile.Size)&"<br>修改时间:"&theFile.DateLastModified&"' style='width:100px;height:70px;CURSOR: hand;' onClick=""javascript:window.opener."&inputname&".value='../" &webuppath&foldername&"/"&theFile.Name& "';window.close();""><br><a href=../" &webuppath&foldername&"/"&theFile.Name& " target=_blank>"&theFile.Name&"</a></td>" & vbcrlf
case "swf"
response.write "<td><img src='../images/flash.gif' style='width:100px;height:70px;CURSOR: hand;' onClick=""javascript:window.opener."&inputname&".value='../" &webuppath&foldername&"/"&theFile.Name& "';window.close();"" border='0'><br><a href../=" &webuppath&foldername&"/"&theFile.Name& " target=_blank>"&theFile.Name&"</a></td>" & vbcrlf
case "wmv","avi","asf","mpg"
response.write "<td><img src='../images/media.gif' style='width:100px;height:70px;CURSOR: hand;' onClick=""javascript:window.opener."&inputname&".value='../" &webuppath&foldername&"/"&theFile.Name& "';window.close();"" border='0'><br><a href=../" &webuppath&foldername&"/"&theFile.Name& " target=_blank>"&theFile.Name&"</a></td>" & vbcrlf
case "rm","ra","ram"
response.write "<td><img src='../images/rm.gif' style='width:100px;height:70px;CURSOR: hand;' onClick=""javascript:window.opener."&inputname&".value='../" &webuppath&foldername&"/"&theFile.Name& "';window.close();"" border='0'><br><a href=../" &webuppath&foldername&"/"&theFile.Name& " target=_blank>"&theFile.Name&"</a></td>" & vbcrlf
case "rar"
response.write "<td><img src='../images/rar.gif' style='width:100px;height:70px;CURSOR: hand;' onClick=""javascript:window.opener."&inputname&".value='../" &webuppath&foldername&"/"&theFile.Name& "';window.close();"" border='0'><br><a href=../" &webuppath&foldername&"/"&theFile.Name& " target=_blank>"&theFile.Name&"</a></td>" & vbcrlf
case "zip"
response.write "<td><img src='../images/zip.gif' style='width:100px;height:70px;CURSOR: hand;' onClick=""javascript:window.opener."&inputname&".value='../" &webuppath&foldername&"/"&theFile.Name& "';window.close();"" border='0'><br><a href=../" &webuppath&foldername&"/"&theFile.Name& " target=_blank>"&theFile.Name&"</a></td>" & vbcrlf
case "exe"
response.write "<td><img src='../images/exe.gif' style='width:100px;height:70px;CURSOR: hand;' onClick=""javascript:window.opener."&inputname&".value='../" &webuppath&foldername&"/"&theFile.Name& "';window.close();"" border='0'><br><a href=../" &webuppath&foldername&"/"&theFile.Name& " target=_blank>"&theFile.Name&"</a></td>" & vbcrlf
case else
response.write "<td><img src='../images/other.gif' style='width:100px;height:70px;CURSOR: hand;' onClick=""javascript:window.opener."&inputname&".value='../" &webuppath&foldername&"/"&theFile.Name& "';window.close();"" border='0'><br><a href=../" &webuppath&foldername&"/"&theFile.Name& " target=_blank>"&theFile.Name&"</a></td>" & vbcrlf
end select
end sub
%>
</body>
</html>


potter2002 2005-12-24
  • 打赏
  • 举报
回复
路过接分 不要白不要
Clnxx 2005-12-24
  • 打赏
  • 举报
回复
学习
创造奇迹9999 2005-12-24
  • 打赏
  • 举报
回复
UP
X_Saint 2005-12-24
  • 打赏
  • 举报
回复
已经习惯来CSDN了
居然忘了MS强大的MSDN
上面的代码就是MSDN的实例代码
稍稍做了修改
希望大家有事没事也多看看MSDN
X_Saint 2005-12-24
  • 打赏
  • 举报
回复
Dim fso, f, f1, fc
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(server.MapPath("/zzz/"))
Set fc = f.Files
For Each f1 in fc
response.Write "<a href='#'>" & f1.name & "</a><BR>"
Next

自己解决。。。
顶者接分

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧