日期:2014-05-16  浏览次数:20830 次

Asp删除无效文件,我的代码错在哪了?请大侠帮忙
本帖最后由 xyciw 于 2012-12-21 15:32:56 编辑
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="conn.asp"-->

<% 

'文件删除函数 
function deletefile(filename) 
if filename<>"" then 
  set fs1=server.CreateObject("scripting.filesystemobject") 
  if fs1.FileExists(filename) then 
   fs1.DeleteFile filename 
  end if 
  set fs1=nothing 
end if      
end function 




function searchfile(fname) 
'查找sys_about表
sql1="SELECT body from sys_about "
set rs1=server.createobject("adodb.recordset")
rs1.open sql1,conn,1,1
if not rs1.eof then 
do while not rs1.eof 

if instr(rs1("body"),fname)>0 then
return true
exit do
exit function
    end if

rs1.movenext
loop
end if
rs1.close
set rs1=nothing

'查找sys_news表
sql2="SELECT body,picurl from sys_news "
set rs2=server.createobject("adodb.recordset")
rs2.open sql2,conn,1,1
if not rs2.eof then 
do while not rs2.eof

if instr(rs2("body"),fname)>0 then
return true
exit do
exit function
end if
if instr(rs2("picurl"),fname)>0 then
return true
exit do
exit function
    end if
rs2.movenext
loop

end if
rs2.close
set rs2=nothing

end function


    function bianli(path) 
        dim fso            'fso对象 
        dim objFolder      '文件夹对象 
        dim objFiles       '文件集合 
        dim objFile        '文件对象 
set fso=Server.CreateObject("Scripting.FileSystemObject")
   
        on error resume next 
        set objFolder=fso.GetFolder(path)'创建文件夹对象 
     
            set objFiles=objFolder.Files 
            for each objFile in objFiles 

if searchfile(objFile.name)=false then
    Response.Write (Server.MapPath("\UploadFile\"+ objFile.name)&"<br>") 
deletefile(Server.MapPath("\UploadFile\"+ objFile.name)) 
end if

            next 
 
        set objFolder=nothing 
        set objSubFolders=nothing 
        set