asp遍历服务器端指定文件夹

<HTML>
<HEAD><TITLE>文件夹内容</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
</HEAD>
<BODY>
<style type="text/css">
.filelist{ clear:both; font-size:12px}
.filelist ul li{list-style:none;float:left; width:180px;}
#filename{ width:400px}
</style>
<%

action=request("action")
filename=request("filename")
foldername=request("foldername")

filePath=request("filePath")
folderPath=request("folderPath")

select case action

case ""
  folderPath=server.MapPath("/upfile")
  call getfloder(folderPath)

Case "delfile"
dim fs
Set fs=Server.CreateObject("Scripting.FileSystemObject")
'filepath=server.MapPath(filename)

if fs.FileExists(filePath) then
fs.DeleteFile(filepath)
end if
set fs=nothing

call MsgBox("文件删除成功!","Back","")
response.End()

Case "openfile"
'foldername=".\"&foldername
'response.Write server.MapPath(foldername)
'response.End()
call getfloder(folderPath)

end select



%>


<%
'文件夹遍历函数
function getfloder(filename)

dim filepath,fso,fileobj,fsofolders,fsofile,folder,file,allFiles,folder1

response.Write("<div class='filelist'><ul><li >文件夹或文件</li><li id='filename'>文件位置</li><li>最后修改时间</li><li>操作</li></ul></div>")
response.Write "<br/><hr/>"

set fs= server.CreateObject("scripting.FileSystemObject")
'set fileobj= fs.GetFolder(server.MapPath(filename))
response.Write "当前所在文件夹:"&Right(folderPath,Len(folderPath)-Instr(folderPath,"\upfile"))

set fileobj= fs.GetFolder(folderPath)
set subfolders=fileobj.SubFolders
Set allFiles = fileobj.files

For Each folder in subfolders
  response.Write("<div class='filelist'><ul><li >文件夹:"&folder.name&"</li><li id='filename'>"&Right(folder.Path,Len(folder.Path)-Instr(folder.Path,"\upfile"))&"</li><li>"&folder.datelastmodified&"</li><li><a href='show.asp?action=openfile&folderPath="&folder.Path&"'>打开</a></li></ul></div>")
Next

response.Write "<br/><hr/>"

For Each file in allFiles
  response.Write("<div class='filelist'><ul><li >文件:"&file.name&"</li><li id='filename'>"&Right(file.Path,Len(file.Path)-Instr(file.Path,"\upfile"))&"</li><li>"&file.datelastmodified&"</li><li><a href='show.asp?action=delfile&filePath="&file.Path&"'>删除<a></li></ul></div>")
Next
response.Write "<br/><hr/>"

response.Write "<a href='javascript:' οnclick='self.location=document.referrer;'>返回上一页</a>"

end function


'子程序名:信息提示窗口
'功能:信息提示,并作返回或者转向
'参数:
'str 提示字符串
'stype 处理类型:Back 返回 GoUrl 转向 Close 关闭
'url 转向方向
'************************
Sub MsgBox(str,stype,url)
 response.write "<script language=javascript>"
 response.write "alert('"&str&"');"
 select case stype
 case "Back"
  response.write "self.location=document.referrer;"
 case "GoUrl"
  response.write "window.location='"&url&"'"
 case "Close"
  response.write "window.close()"
 end select
 response.write "</script>"
End Sub

%>
</Body>
</HTML>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值