<p>FSO按文件大小浏览文件目录并进行删除操作的方法</p>
<p>下面介绍FSO按文件大小浏览文件目录并进行删除操作的方法:</p>
<p><%@ Language=VBScript %><br />
<%Server.ScriptTimeout=50000%></p>
<p><br />
<br />
<br />
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"><br />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"><br />
<br />
</p>
<p><br />
<%<br />
function JudgeParaRegular(intID)<br />
if intID<>"" and isnumeric(intID) then<br />
JudgeParaRegular=intId<br />
else<br />
Response.Write "输入错误!"<br />
Response.End<br />
end if<br />
end function<br />
intFileSize=JudgeParaRegular(Request.QueryString("intFileSize"))<br />
strPath=Request.QueryString("strPath")<br />
if instr(strPath,":")=0 then strPath=server.MapPath(strPath)<br />
%><br />
<%<br />
function deletefiles(path)<br />
on error resume next<br />
Set fs=Server.CreateObject("Scripting.FileSystemObject")<br />
if fs.FileExists(path) then<br />
fs.DeleteFile path,True<br />
response.write "成功删除"&path<br />
else<br />
response.write "文件不存在!"<br />
end if<br />
Set fs=nothing<br />
if Err.number<>0 then Response.Write Err.number<br />
end function<br />
strFile=request("strFile")<br />
if request("strFile")<>"" then<br />
deletefiles strFile<br />
end if</p>
<p></p>
<p>%></p>
<p><%<br />
function ListFolderFiles(strPath,intFileSize,intFlag)<br />
strOriginPath= Request.ServerVariables("Script_Name")& "?strPath=" &Request.QueryString("strPath") & "&intFileSize="&Request.QueryString("intFileSize")<br />
if strPath<>"" then<br />
if intFlag=0 then<br />
intFlag=intFlag+1<br />
end if<br />
Set objFs=Server.CreateObject("Scripting.FileSystemObject")<br />
Set objFdir=objFs.GetFolder(strPath)<br />
strParentPath= objFs.GetParentFolderName(strPath)<br />
for each strSubFiles in objFdir.files<br />
if strSubFiles.size /(1024^2)>=intFileSize then<br />
Response.Write "" & vbcrlf<br />
Response.Write "" & replace(strNullTran(strSubFiles),strNullTran(strSubFiles.Name),"<b>"&strNullTran(strSubFiles.Name)&"</b>") & "" & vbcrlf<br />
Response.Write ""& strNullTran(FormatNumber(strSubFiles.size /(1024^2),2)) &" MB" & vbcrlf<br />
Response.Write "" & strNullTran(strSubFiles.type) & "" & vbcrlf<br />
Response.Write "" & strNullTran(strSubFiles.datelastmodified) & "" & vbcrlf<br />
Response.Write "<a href=""& strOriginPath & "&strFile="&strNullTran(strSubFiles)&""><img 127.0.0.1="" 19="" 2007-4="" align="absmiddle" beyondpic="" border="0" br="" files="" http:="" src="<a href=" vbcrlf="" /> Response.Write "" & vbcrlf<br />
intFlag=intFlag+strSubFiles.size<br />
end if<br />
next<br />
for each strSubFolders in objFdir.SubFolders<br />
if intFlag=0 then intFlag=1<br />
ListFolderFiles strSubFolders,intFileSize,intFlag<br />
next<br />
else<br />
Response.Write "输入错误!"<br />
end if<br />
ListFolderFiles=intFlag<br />
end function<br />
function strNullTran(str)<br />
if isnull(str) or str="" then<br />
strNullTran=" "<br />
else<br />
strNullTran=str<br />
end if<br />
end function<br />
Response.Write "" & vbcrlf<br />
Response.Write "" & vbcrlf<br />
Response.Write "" & vbcrlf<br />
Response.Write "" & vbcrlf<br />
Response.Write "" & vbcrlf<br />
Response.Write "" & vbcrlf<br />
Response.Write "" & vbcrlf<br />
Response.Write "" & vbcrlf<br />
intFlag=ListFolderFiles(strPath,CDbl(intFileSize),0)<br />
Response.Write "" & vbcrlf<br />
Response.Write "</a></p>
<table border="1" cellpadding="1" cellspacing="1" width="100%">
<tbody>
<tr>
<td><a href=""& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"">文件名及路径</a></td>
<td align="center"><a href=""& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"">大小</a></td>
<td align="center"><a href=""& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"">类别</a></td>
<td align="center"><a href=""& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"">修改时间</a></td>
<td align="center"><a href=""& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"">删除</a></td>
</tr>
<tr>
<td align="right"><a href=""& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"">总计:</a></td>
<td colspan="4"><a href=""& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"">"&formatNumber((intFlag-1)/(1024^2),2) &" MB</a></td>
</tr>
</tbody>
</table>
<p>
<p>
<p><a href=""& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"">" & vbcrlf<br />
%></a></p>
</p>
</p>