使用FSO按文件大小浏览文件目录并进行删除操作
程序员文章站
2022-05-28 16:26:09
<%@ language=vbscript %>
<%server.scripttimeout=50000%>
&l...
<%@ language=vbscript %>
<%server.scripttimeout=50000%>
<html>
<head>
<meta name="generator" content="microsoft visual studio 6.0">
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<body>
<%
function judgepararegular(intid)
if intid<>"" and isnumeric(intid) then
judgepararegular=intid
else
response.write "输入错误!"
response.end
end if
end function
intfilesize=judgepararegular(request.querystring("intfilesize"))
strpath=request.querystring("strpath")
if instr(strpath,":")=0 then strpath=server.mappath(strpath)
%>
<%
function deletefiles(path)
on error resume next
set fs=server.createobject("scripting.filesystemobject")
if fs.fileexists(path) then
fs.deletefile path,true
response.write "成功删除"&path
else
response.write "文件不存在!"
end if
set fs=nothing
if err.number<>0 then response.write err.number
end function
strfile=request("strfile")
if request("strfile")<>"" then
deletefiles strfile
end if
%>
<%
function listfolderfiles(strpath,intfilesize,intflag)
stroriginpath= request.servervariables("script_name")& "?strpath=" &request.querystring("strpath") & "&intfilesize="&request.querystring("intfilesize")
if strpath<>"" then
if intflag=0 then
intflag=intflag+1
end if
set objfs=server.createobject("scripting.filesystemobject")
set objfdir=objfs.getfolder(strpath)
strparentpath= objfs.getparentfoldername(strpath)
for each strsubfiles in objfdir.files
if strsubfiles.size /(1024^2)>=intfilesize then
response.write "<tr>" & vbcrlf
response.write "<td>" & replace(strnulltran(strsubfiles),strnulltran(strsubfiles.name),"<b>"&strnulltran(strsubfiles.name)&"</b>") & "</td>" & vbcrlf
response.write "<td>"& strnulltran(formatnumber(strsubfiles.size /(1024^2),2)) &" mb</td>" & vbcrlf
response.write "<td>" & strnulltran(strsubfiles.type) & "</td>" & vbcrlf
response.write "<td>" & strnulltran(strsubfiles.datelastmodified) & "</td>" & vbcrlf
response.write "<td><a href='"& stroriginpath & "&strfile="&strnulltran(strsubfiles)&"'><img align=absmiddle border=0 src='images/delete.gif'></a></td>" & vbcrlf
response.write "</tr>" & vbcrlf
intflag=intflag+strsubfiles.size
end if
next
for each strsubfolders in objfdir.subfolders
if intflag=0 then intflag=1
listfolderfiles strsubfolders,intfilesize,intflag
next
else
response.write "<tr><td colspan=5>输入错误!</td></tr>"
end if
listfolderfiles=intflag
end function
function strnulltran(str)
if isnull(str) or str="" then
strnulltran=" "
else
strnulltran=str
end if
end function
response.write "<table width=100% border=1 cellspacing=1 cellpadding=1>" & vbcrlf
response.write "<tr>" & vbcrlf
response.write "<td>文件名及路径</td>" & vbcrlf
response.write "<td align=center>大小</td>" & vbcrlf
response.write "<td align=center>类别</td>" & vbcrlf
response.write "<td align=center>修改时间</td>" & vbcrlf
response.write "<td align=center>删除</td>" & vbcrlf
response.write "</tr>" & vbcrlf
intflag=listfolderfiles(strpath,cdbl(intfilesize),0)
response.write "<tr><td align=right>总计:</td><td colspan=4>"&formatnumber((intflag-1)/(1024^2),2) &" mb</td></tr>" & vbcrlf
response.write "</table>" & vbcrlf
%>
</body>
</html>
<%server.scripttimeout=50000%>
<html>
<head>
<meta name="generator" content="microsoft visual studio 6.0">
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<body>
<%
function judgepararegular(intid)
if intid<>"" and isnumeric(intid) then
judgepararegular=intid
else
response.write "输入错误!"
response.end
end if
end function
intfilesize=judgepararegular(request.querystring("intfilesize"))
strpath=request.querystring("strpath")
if instr(strpath,":")=0 then strpath=server.mappath(strpath)
%>
<%
function deletefiles(path)
on error resume next
set fs=server.createobject("scripting.filesystemobject")
if fs.fileexists(path) then
fs.deletefile path,true
response.write "成功删除"&path
else
response.write "文件不存在!"
end if
set fs=nothing
if err.number<>0 then response.write err.number
end function
strfile=request("strfile")
if request("strfile")<>"" then
deletefiles strfile
end if
%>
<%
function listfolderfiles(strpath,intfilesize,intflag)
stroriginpath= request.servervariables("script_name")& "?strpath=" &request.querystring("strpath") & "&intfilesize="&request.querystring("intfilesize")
if strpath<>"" then
if intflag=0 then
intflag=intflag+1
end if
set objfs=server.createobject("scripting.filesystemobject")
set objfdir=objfs.getfolder(strpath)
strparentpath= objfs.getparentfoldername(strpath)
for each strsubfiles in objfdir.files
if strsubfiles.size /(1024^2)>=intfilesize then
response.write "<tr>" & vbcrlf
response.write "<td>" & replace(strnulltran(strsubfiles),strnulltran(strsubfiles.name),"<b>"&strnulltran(strsubfiles.name)&"</b>") & "</td>" & vbcrlf
response.write "<td>"& strnulltran(formatnumber(strsubfiles.size /(1024^2),2)) &" mb</td>" & vbcrlf
response.write "<td>" & strnulltran(strsubfiles.type) & "</td>" & vbcrlf
response.write "<td>" & strnulltran(strsubfiles.datelastmodified) & "</td>" & vbcrlf
response.write "<td><a href='"& stroriginpath & "&strfile="&strnulltran(strsubfiles)&"'><img align=absmiddle border=0 src='images/delete.gif'></a></td>" & vbcrlf
response.write "</tr>" & vbcrlf
intflag=intflag+strsubfiles.size
end if
next
for each strsubfolders in objfdir.subfolders
if intflag=0 then intflag=1
listfolderfiles strsubfolders,intfilesize,intflag
next
else
response.write "<tr><td colspan=5>输入错误!</td></tr>"
end if
listfolderfiles=intflag
end function
function strnulltran(str)
if isnull(str) or str="" then
strnulltran=" "
else
strnulltran=str
end if
end function
response.write "<table width=100% border=1 cellspacing=1 cellpadding=1>" & vbcrlf
response.write "<tr>" & vbcrlf
response.write "<td>文件名及路径</td>" & vbcrlf
response.write "<td align=center>大小</td>" & vbcrlf
response.write "<td align=center>类别</td>" & vbcrlf
response.write "<td align=center>修改时间</td>" & vbcrlf
response.write "<td align=center>删除</td>" & vbcrlf
response.write "</tr>" & vbcrlf
intflag=listfolderfiles(strpath,cdbl(intfilesize),0)
response.write "<tr><td align=right>总计:</td><td colspan=4>"&formatnumber((intflag-1)/(1024^2),2) &" mb</td></tr>" & vbcrlf
response.write "</table>" & vbcrlf
%>
</body>
</html>