注册 登录
编程论坛 ASP技术论坛

求助 关于ASP 批量删除的问题

cb326571513 发布于 2013-08-16 11:38, 506 次点击
程序代码:
<%if trim(session("username"))="" then response.Redirect("../index.asp")%>
<!--#include file="include/conn.asp"-->

<%

Const EnableUploadFile="Yes"        '是否开放文件上传
Const MaxFileSize=200        '上传文件大小限制
Const SaveUpFilesPath="uploadfile"        '存放上传文件的目录
Const UpFileType="gif|jpg|bmp|png|swf|doc|rar"        '允许的上传文件类型
Const SessionTimeout=30        'Session会话的保持时间



%>

<!--#include file="function.asp"-->


<%Const MaxPerPage=15
dim strFileName
dim totalPut,CurrentPage,TotalPages
dim UploadDir,TruePath,fso,theFolder,theFile,whichfile,thisfile,FileCount,TotleSize
strFileName
="Admin_Upload.asp"

if request("page")<>"" then
    currentPage
=cint(request("page"))
else
    currentPage
=1
end if

path
= request.QueryString("path")        '读取路径参数
if path = "" then path = SaveUpFilesPath  end if '不传参数时默认读根目录
rootpath = Server.MapPath(path)
if right(path,1)<>"/" then
    UploadDir
=path & "/"
else
    UploadDir
=path
end if
TruePath
=Server.MapPath(UploadDir)
If not IsObjInstalled("Scripting.FileSystemObject") Then
    Response.Write
"<b><font color=red>你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能</font></b>"
Else
   
set fso=CreateObject("Scripting.FileSystemObject")
   
if request("Action")="Del" then
        delarr
=Split(request("FileName"),",")
        
For i = LBound(delarr) To UBound(delarr)
        whichfile
=server.mappath(delarr(i))
        
Set thisfile = fso.GetFile(whichfile)
        thisfile.Delete
True
        
next
        response.redirect
"Admin_Upload.asp"
   
end if

%>
<script language="JavaScript">
function ConfirmDel()
{
if (confirm("你真的要删除此文件吗!"))
   
return true;
else
   
return false;
}
</script>
<script language="JavaScript" type="text/JavaScript">
function check()
{
  
if (document.form1.FileName.value=="")
  {
    alert(
"请选择要删除的文件!");
   
return false;
  }
}
</script>
<script language=javascript>
function mm()
{
   
var a = document.getElementsByTagName("input");
   
if(a[0].checked==true){
   
for (var i=0; i<a.length; i++)
      
if (a[i].type == "checkbox") a[i].checked = false;
   }
   
else
   {
   
for (var i=0; i<a.length; i++)
      
if (a[i].type == "checkbox") a[i].checked = true;
   }
}
</script>
<link href="include/Forum_admin.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">


<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="top"> <br>
<%
  
if fso.FolderExists(TruePath)then
    FileCount
=0
    TotleSize
=0
   
Set theFolder=fso.GetFolder(TruePath)
   
For Each theFile In theFolder.Files
        FileCount
=FileCount+1
        TotleSize
=TotleSize+theFile.Size
   
next
    totalPut
=FileCount
   
if currentpage<1 then
           currentpage
=1
      
end if
      
if (currentpage-1)*MaxPerPage>totalput then
        
if (totalPut mod MaxPerPage)=0 then
              currentpage
= totalPut \ MaxPerPage
         
else
              currentpage
= totalPut \ MaxPerPage + 1
        
end if

   
end if
   
if currentPage=1 then
        
'showpage2 strFileName,totalput,MaxPerPage
        showContent        
        showpage2 strFileName,totalput,MaxPerPage
        response.write
"<br><div align='center' style='height:50px;'>本页共显示 <b>" & FileCount & "</b> 个文件,占用 <b>" & TotleSize\1024 & "</b> KB</div>"
      
else
              
if (currentPage-1)*MaxPerPage<totalPut then
            showpage2 strFileName,totalput,MaxPerPage
            showContent        
            showpage2 strFileName,totalput,MaxPerPage
            response.write
"<br><div align='center' style='height:50px;'>本页共显示 <b>" & FileCount & "</b> 个文件,占用 <b>" & TotleSize\1024 & "</b> KB</div>"
           
else
            currentPage
=1
            showpage2 strFileName,totalput,MaxPerPage
            showContent        
            showpage2 strFileName,totalput,MaxPerPage
            response.write
"<br><div align='center' style='height:50px;'>本页共显示 <b>" & FileCount & "</b> 个文件,占用 <b>" & TotleSize\1024 & "</b> KB</div>"
        
end if
   
end if
  
else
    response.write
"找不到文件夹!可能是配置有误!"
  
end if
end if

sub showContent()
      
dim c
    FileCount
=0
    TotleSize
=0
%>
     

      <table width="95%"  border="1" cellpadding="0" cellspacing="0" class="tableBorder" style="border-collapse: collapse;">
        <form name="form1" method="post" action="Admin_Upload.asp?Action=Del"  onsubmit="return check()">
         <tr bgcolor="A4B6D7" class="title">
          <td height="35" colspan="7" align="center" bgcolor="c1eafe" class="td2"><strong>上 传 文 件 管 理</strong></td>
        </tr>
        <tr bgcolor="#f0f9fe" class="title">
          <td width="61" height="35" align="center" bgcolor="#f0f9fe">选择</td>
          <td align="center">图片</td>
          <td width="172" align="center" bgcolor="#f0f9fe">文件名</td>
          <td width="119" height="20" align="center" bgcolor="#f0f9fe">文件大小</td>
          <td width="109" height="20" align="center" bgcolor="#f0f9fe">文件类型</td>
          <td width="168" height="20" align="center" bgcolor="#f0f9fe">最后修改时间</td>
          <td width="40" height="20" align="center">操作</td>
        </tr>
        <%
        n
= theFolder.subfolders.count
        
ReDim folderArr(n)
        
dim itemArr(2)
        
'循环将文件夹放入数组
        for each obj in theFolder.subfolders
            itemArr(
0) = obj.name
            itemArr(
1) = obj.ParentFolder.name
            itemArr(
2) = obj.DateCreated
            folderArr(i)
= itemArr
            i
=i+1
        
next
   
for m = 0 to i-1
    folder
= folderArr(m)
    tmppath
= path&"/"&folder(0)%>
   
   
    <tr style="" onMouseOver="this.style.background='#c1eafe';" onMouseOut="this.style.background='#fff';">
    <td height=30>&nbsp;</td>
       <td>&nbsp;</td>
    <td align="center"><%=folder(0)%></td>
    <td>&nbsp;</td>
    <td align="center">文件夹</td>
    <td align="center"><%=folder(2)%></td>
    <td align="center"><a href="?path=<%=tmppath%>">查看</a></td>
   </tr>
  
  
    <%next

For Each theFile In theFolder.Files
    c
=c+1
   
if FileCount>=MaxPerPage then
        
exit for
   
elseif c>MaxPerPage*(CurrentPage-1) then
%>
        <tr class="tdbg" onMouseOver="this.style.background='#c1eafe';" onMouseOut="this.style.background='#fff';">
          <td height="25" align="center"><input name="FileName" type="checkbox" id="FileName" value="<%=UploadDir & theFile.Name%>" /></td>
          <td align="center"><img src="<%=(UploadDir & theFile.Name)%>" class=upimgab></td>
          <td height="25" align="center"><a href="<%=(UploadDir & theFile.Name)%>"  title="" target="_blank"><strong>&nbsp;<%=theFile.Name%></strong></a></td>
          <td width="110" height="25" align="center"><%=theFile.size\1024%>KB</td>
          <td width="110" height="25" align="center"><%=theFile.type%></td>
          <td align="center"><%=theFile.DateLastModified%></td>
          <td width="60" height="25" align="center"><a href="Admin_Upload.asp?Action=Del&FileName=<%=UploadDir & theFile.Name%>" onclick="return ConfirmDel()">删除</a></td>
        </tr>
        <%
        FileCount
=FileCount+1
        TotleSize
=TotleSize+theFile.Size
   
end if
Next
%>
        <tr bgcolor="#ECF5FF" class="tdbg">
          <td height="25" colspan="7" align="center"> <input type="submit" name="Submit" value="删除所选" onclick="return ConfirmDel()">
            全选
            <input type="checkbox" name="checkbox" value="Check All" onClick="mm()"></td>
          </tr>
</form>
      </table>
      <%
end sub
%> </td>
  </tr>
</table>
<%
sub showpage2(sfilename,totalnumber,maxperpage)
   
dim n, i,strTemp
   
if totalnumber mod maxperpage=0 then
        n
= totalnumber \ maxperpage
      
else
        n
= totalnumber \ maxperpage+1
      
end if
      strTemp
= "<table align='center'><form name='showpages' method='Post' action='" & sfilename & "'><tr><td>"
    strTemp
=strTemp & "共 <b>" & totalnumber & "</b> 个文件,占用 <b>" & TotleSize\1024 & "</b> KB&nbsp;&nbsp;&nbsp;"
    sfilename
=JoinChar(sfilename)
      
if CurrentPage<2 then
            strTemp
=strTemp & "首页 上一页&nbsp;"
      
else
            strTemp
=strTemp & "<a href='" & sfilename & "page=1&path="&path&"'>首页</a>&nbsp;"
            strTemp
=strTemp & "<a href='" & sfilename & "page=" & (CurrentPage-1) & "&path="&path&"'>上一页</a>&nbsp;"
      
end if

      
if n-currentpage<1 then
            strTemp
=strTemp & "下一页 尾页"
      
else
            strTemp
=strTemp & "<a href='" & sfilename & "page=" & (CurrentPage+1) & "&path="&path&"'>下一页</a>&nbsp;"
            strTemp
=strTemp & "<a href='" & sfilename & "page=" & n & "&path="&path&"'>尾页</a>"
      
end if
       strTemp
=strTemp & "&nbsp;页次:<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "
    strTemp
=strTemp & "&nbsp;<b>" & maxperpage & "</b>" & "个文件/页"
    strTemp
=strTemp & "&nbsp;转到:<select name='page' size='1' onchange='javascript:submit()'>"  
   
for i = 1 to n  
           strTemp
=strTemp & "<option value='" & i & "'"
        
if cint(CurrentPage)=cint(i) then strTemp=strTemp & " selected "
        strTemp
=strTemp & ">第" & i & "页</option>"  
   
next
    strTemp
=strTemp & "</select>"
    strTemp
=strTemp & "</td></tr></form></table>"
    response.write strTemp
end sub
%>


如果只删除一个,是好的。但是如果点前面的选框来多个同时删除的话,就会报错。但是报错后还是会删除选取的最上面的那一个。

在读取到这一块的时候 (第48行)
if request("Action")="Del" then
            delarr=Split(request("FileName"),",")
                For i = LBound(delarr) To UBound(delarr)
                whichfile=server.mappath(delarr(i))
                Set thisfile = fso.GetFile(whichfile)
                thisfile.Delete True
                next
                response.redirect "Admin_Upload.asp"
        end if

会报错,显示的是
Microsoft VBScript 运行时错误 '800a0035'

文件未找到

\wwwroot\ryzs\admin\Admin_Upload.asp, line 48

求高手帮解决一下。
0 回复
1