使用FSO按文件大小浏览文件目录并进行删除操作

Kiver 发布于2003-11-9 10:39 1036 次浏览 0 位用户参与讨论   [复制分享主题]

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区

您需要 登录 才可以下载或查看,没有账号?註冊

x
  y' ~7 O2 U$ a; I* @' C; t

- n0 l1 S3 q: C4 r
- A( e: L/ x$ n' n9 H- m $ t7 R2 ?& O8 V  q
) e4 t. x6 J, Q) j
<%@ Language=VBScript %>
+ l" M. B  d$ Y4 o% w/ x' h- [<%Server.ScriptTimeout=50000%>
6 z0 ]3 F8 g5 z- B7 h; V! ?<HTML>- e* g/ C# ~0 V; U" N; I9 e& e4 o
<HEAD>6 O( I6 g- r' K, H7 C' m
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
3 [4 O. x5 V) u) K<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
. n2 K. x8 |7 I2 Y/ }# o7 o' ]( b# p</HEAD>% Z/ D6 n- Q) B5 c
<BODY>9 P5 u; n4 V& ^& W" i$ J
<%1 D; t( h' o6 x1 D
function JudgeParaRegular(intID)% ~; y6 L: K6 x9 U9 M1 m
if intID<>"" and isnumeric(intID) then
( m) c( y9 A+ E. m9 ]4 Z! `$ A+ CJudgeParaRegular=intId2 Y0 b) O$ f; _
else# l2 `! Q0 A% l5 U$ b- `2 |
Response.Write "输入错误!" ! Y& ?* J# ]: b( {1 g/ y* V
Response.End % F' I% a* \- z. B
end if# R- U! P# b1 y# O: K% o
end function
, c- |+ I0 A$ F4 w! EintFileSize=JudgeParaRegular(Request.QueryString("intFileSize"))9 S+ @, t* A2 R3 [; }2 p2 F6 r! J
strPath=Request.QueryString("strPath")
, R5 f6 M7 Q8 i# T5 Kif instr(strPath,":")=0 then strPath=server.MapPath(strPath)
9 U; W# i- e8 W) n1 r$ X%>
9 [3 I) U4 _/ s8 ^<%
  L& ]' S# t5 x, m( l# I' }& {function deletefiles(path)8 v, l4 @2 }/ h7 r0 R% F" V
on error resume next8 W4 L# M! L+ B) c
Set fs=Server.CreateObject("Scripting.FileSystemObject")& i7 {( X* v, r1 q3 |0 l: h7 c
if fs.FileExists(path) then
2 k; Q& N% [* j9 ]2 Mfs.DeleteFile path,True
1 I( Q/ ^7 V! G" T1 A! {response.write "成功删除"&path
- V, `: l* o' f6 k8 Delse. q# O. j9 N0 q$ i8 {% v  y# Q
response.write "文件不存在!"- D* W) x7 y2 i5 @) s; ^
end if6 }/ h; [( F4 N/ n9 X0 q
Set fs=nothing
' K1 K7 D, k/ ~( V) b# G& w. iif Err.number<>0 then Response.Write Err.number ; w; `1 J  U1 o2 e
end function) @& j7 j. W& g8 t. N& h
strFile=request("strFile")$ a) u; l' ]; \2 Q: b
if request("strFile")<>"" then2 v2 s3 d# f' X8 D( s; I, T2 \
deletefiles strFile' @( M4 @! T! E& C- ?
end if 3 p% G% Y- n$ W' f

  g( n0 R5 s9 D%>
8 C$ g) M) d: s$ L2 D, l7 F
5 }! D. f$ K& I0 j# |. {2 y/ ?" s<%) y6 q4 q% Z* ?  J2 @2 ?2 x
function ListFolderFiles(strPath,intFileSize,intFlag)
' d$ t/ H- a& {, X3 Z+ {( ~strOriginPath= Request.ServerVariables("Script_Name")& "?strPath=" &Request.QueryString("strPath") & "&intFileSize="&Request.QueryString("intFileSize")
( E1 A/ o  v( N4 Pif strPath<>"" then
6 Q7 b% f' [. y: h; V1 Vif intFlag=0 then
" j" |" \& g+ sintFlag=intFlag+17 `( a# C" e' C0 g, H
end if : G" [1 S" y6 F, N7 y: G
Set objFs=Server.CreateObject("Scripting.FileSystemObject")
- L% D1 y! M0 V% JSet objFdir=objFs.GetFolder(strPath); ~, e) J$ h5 W+ X4 l; \
strParentPath= objFs.GetParentFolderName(strPath)$ {  u  \/ A: o  o" H
for each strSubFiles in objFdir.files5 o0 d+ g+ z6 \1 `: s
if strSubFiles.size /(1024^2)>=intFileSize then# Q, n  y7 R" J) S. ~1 ]! K/ N
Response.Write "<TR>" & vbcrlf
0 ^  H9 x; O! RResponse.Write "<TD>" & replace(strNullTran(strSubFiles),strNullTran(strSubFiles.Name),"<b>"&strNullTran(strSubFiles.Name)&"</b>") & "</TD>" & vbcrlf
+ k4 L: C$ h4 pResponse.Write "<TD>"& strNullTran(FormatNumber(strSubFiles.size /(1024^2),2)) &" MB</TD>" & vbcrlf! d4 L/ v3 R2 O6 }- V1 ?
Response.Write "<TD>" & strNullTran(strSubFiles.type) & "</TD>" & vbcrlf' D) l, n8 M: P4 o
Response.Write "<TD>" & strNullTran(strSubFiles.datelastmodified) & "</TD>" & vbcrlf
1 K1 ?  W2 C' D- _- ]3 G7 DResponse.Write "<TD><A HREF='"& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"'><img align=absmiddle border=0 src='images/delete.gif'></A></TD>" & vbcrlf9 y# A7 V- }7 w
Response.Write "</TR>" & vbcrlf
) q" m  s& ^7 ~3 Z6 X& |5 h3 O% v! OintFlag=intFlag+strSubFiles.size# y4 {1 j, X% Z2 V+ [. W
end if* j, d; z2 G9 n  Z2 S% S. n# s
next6 X$ p- L9 p8 X, X1 ^7 C/ F8 {) O$ `* l
for each strSubFolders in objFdir.SubFolders5 N) d! w! q% Z8 E3 o. j, u
if intFlag=0 then intFlag=1
9 J, g0 q! I: h; E- tListFolderFiles strSubFolders,intFileSize,intFlag* H  R3 W5 J" I/ p) A* |
next3 O+ f0 J  f9 a4 t
else
1 L" c% J3 W3 o2 a! e+ qResponse.Write "<tr><td colspan=5>输入错误!</td></tr>"& W6 _& t) z' U, m, S
end if
% i% }! L  o- Z6 ^, |$ SListFolderFiles=intFlag
5 Q" ~0 P8 x. k7 T+ _end function7 R3 b/ e# |4 Y
function strNullTran(str)
1 {- k$ `. m- T' U1 S1 Q' O) `5 ]if isnull(str) or str="" then
3 K7 Y1 }; C8 H5 o/ T( R" mstrNullTran=" "
+ R9 N& z- E/ s+ A& i5 Qelse( f# h4 d  T0 \5 O8 D% D
strNullTran=str
5 |$ ?- Y. s. r( C" Iend if7 y3 E$ h  h3 K, w% o# o
end function
( D8 }7 r2 I9 ~/ l' Q' _Response.Write "<TABLE WIDTH=100% BORDER=1 CELLSPACING=1 CELLPADDING=1>" & vbcrlf7 c" p- E- ~9 p8 J5 d" {2 B9 `, z$ t
Response.Write "<TR>" & vbcrlf
5 ~. a  W9 T, v* P/ }Response.Write "<TD>文件名及路径</TD>" & vbcrlf! H$ \5 D0 a" Q. S0 R: K& ]) y
Response.Write "<TD align=center>大小</TD>" & vbcrlf
& R) I. {4 e% }Response.Write "<TD align=center>类别</TD>" & vbcrlf; u/ r6 g3 @$ f/ W, ^
Response.Write "<TD align=center>修改时间</TD>" & vbcrlf& h, ?4 L4 {: q% u8 _7 G2 T& c
Response.Write "<TD align=center>删除</TD>" & vbcrlf
0 U; N5 G  C2 n7 H' JResponse.Write "</TR>" & vbcrlf
4 O  t* I* y% a3 Q! q. A$ PintFlag=ListFolderFiles(strPath,CDbl(intFileSize),0)
" d- g1 u5 h: g9 J$ nResponse.Write "<tr><td align=right>总计:</td><td colspan=4>"&formatNumber((intFlag-1)/(1024^2),2) &" MB</td></tr>" & vbcrlf
  v0 W! `9 u7 b. ^Response.Write "</TABLE>" & vbcrlf" W  x5 q( u: F) O  R
%># ^) d7 e1 X' }9 Y" }/ e; B
</BODY>
! O' b+ b8 f3 T& H# d</HTML>
1 i& T+ _# _8 M, C! {* s! m. B7 ]% n
/ g3 V$ W2 E5 A/ d 2 \7 D* r3 ~7 S% T
您需要登录后才可以回帖 登录 | 註冊

本版积分规则

快速
回复
返回
列表
返回
顶部