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

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

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

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

x
3 U8 n2 P5 n) M. p7 r% f' j- W

* D: c$ Z1 h. P( A& P0 ^! g8 }' }! k# u4 H1 R

, g- h# j( q  w' R$ m( B, l1 ~4 d
<%@ Language=VBScript %>( m- k  }9 n1 Q0 m2 v  H$ B
<%Server.ScriptTimeout=50000%>8 p- ^( i. n2 R; x7 C3 I
<HTML>" v, a3 ?0 J0 h& @$ n  g
<HEAD>
: ?4 C! J# J0 i2 s% v<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
( @5 z: W- h) T) _' q. |<meta http-equiv="Content-Type" content="text/html; charset=gb2312">0 H. J0 j. x$ N* h- k" A; R: n5 m
</HEAD>
. j% `8 T$ v2 e# ?! k<BODY>
0 Y" e3 i, A& W* c, s<%. D; y9 ~, R: d2 e7 J
function JudgeParaRegular(intID)" [2 S) X$ B$ v9 E- w* P* C: K
if intID<>"" and isnumeric(intID) then
9 k0 F( {- R. g2 PJudgeParaRegular=intId
  O0 K( L# ~9 \0 c5 telse( A# D  h+ j1 g. k3 p1 Y( P' t' C
Response.Write "输入错误!"
8 y1 [8 j2 P$ WResponse.End
7 K* O: p: b  Y3 k2 @) j3 vend if
8 m- P% l& N0 E5 ~end function7 `7 m8 f2 d' Z( O8 J) z
intFileSize=JudgeParaRegular(Request.QueryString("intFileSize"))9 z# x1 p7 c) t. {6 O
strPath=Request.QueryString("strPath")
8 Y* a' [7 X& }% l" Xif instr(strPath,":")=0 then strPath=server.MapPath(strPath)! q. S5 Z5 U5 V
%>) d- @. L( l& m1 ?$ ~& c/ J
<%* Z5 J- D9 m- }
function deletefiles(path)" f5 n; c6 M, t3 C
on error resume next
$ n  Z8 B/ D$ S6 qSet fs=Server.CreateObject("Scripting.FileSystemObject"): m5 S& I' O% h+ C9 X
if fs.FileExists(path) then
0 X3 ?1 s" {9 p7 y& |fs.DeleteFile path,True8 H  p" v" f* k" b: _6 ]! Y$ G
response.write "成功删除"&path( Z+ w2 F5 |2 H" C+ a4 k. P( H
else# G) G% U$ V2 X- |; v) P9 F
response.write "文件不存在!"; K& Y# A$ l( n1 A% N
end if
( I$ r; \$ m1 i8 s% DSet fs=nothing" I  q- a# q) ~  E
if Err.number<>0 then Response.Write Err.number
* E7 ~" h. d- ~end function
. O0 ]. h, |% ~) lstrFile=request("strFile")2 x& Y! `" ?1 O8 b/ B. K
if request("strFile")<>"" then3 C$ B, W6 P. {8 ]) J
deletefiles strFile% [' q* N" c. k$ t  \
end if 9 y9 {. \9 U! s6 m# m

6 C5 m1 ^4 r, z0 W* W+ E& N. @%>
+ Q4 t$ S. F* i& V! Z* K+ |* V* V1 }
<%5 ~! t* \6 K: _/ \) u% [# J
function ListFolderFiles(strPath,intFileSize,intFlag)) _/ M* L7 j9 Q/ e6 D4 t
strOriginPath= Request.ServerVariables("Script_Name")& "?strPath=" &Request.QueryString("strPath") & "&intFileSize="&Request.QueryString("intFileSize")2 ?2 B# {- \8 l
if strPath<>"" then
8 ]2 a) j! g; t. a. k4 R4 V) Rif intFlag=0 then. h& k5 p) L1 L$ R! v  q
intFlag=intFlag+1$ N; X0 e. j0 M& n2 ?# d
end if
6 @& T1 r! ^4 u0 [0 d$ GSet objFs=Server.CreateObject("Scripting.FileSystemObject")
0 W% y# U# }0 m5 ]* V! wSet objFdir=objFs.GetFolder(strPath)" S: y1 |" \2 v, l- z
strParentPath= objFs.GetParentFolderName(strPath)/ r* }3 c+ N' B  F
for each strSubFiles in objFdir.files3 I2 e9 F& z' v9 K( R) {  o
if strSubFiles.size /(1024^2)>=intFileSize then/ B' D6 m. n7 h$ X9 r6 q
Response.Write "<TR>" & vbcrlf, F" U+ T2 i: H7 J3 P( C, a& Z8 ^
Response.Write "<TD>" & replace(strNullTran(strSubFiles),strNullTran(strSubFiles.Name),"<b>"&strNullTran(strSubFiles.Name)&"</b>") & "</TD>" & vbcrlf; K; b& x4 t; g6 n
Response.Write "<TD>"& strNullTran(FormatNumber(strSubFiles.size /(1024^2),2)) &" MB</TD>" & vbcrlf
; e# v5 b* C8 R) b" I5 Q( cResponse.Write "<TD>" & strNullTran(strSubFiles.type) & "</TD>" & vbcrlf
  t$ F9 R; Z  F) ?* PResponse.Write "<TD>" & strNullTran(strSubFiles.datelastmodified) & "</TD>" & vbcrlf+ y7 b+ X- T3 l6 P1 P8 s$ U. k
Response.Write "<TD><A HREF='"& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"'><img align=absmiddle border=0 src='images/delete.gif'></A></TD>" & vbcrlf( B) Z! h, R7 l* L, E8 J* K
Response.Write "</TR>" & vbcrlf
; R- u1 H( w% W5 u* |5 V1 B4 pintFlag=intFlag+strSubFiles.size
- f1 f3 R7 S4 r' Z* m. aend if# m' M4 Y, M( v* `0 {; w# w0 ?
next
3 h& v. v2 m: M, d; G, Nfor each strSubFolders in objFdir.SubFolders
7 ?! ]. |% G3 rif intFlag=0 then intFlag=1  v/ l! v3 ?( W+ r8 f2 n- ~
ListFolderFiles strSubFolders,intFileSize,intFlag
% D7 Y6 U! `* c9 n4 D7 J3 ^" pnext6 G5 E' v- h/ |% V
else0 m( w' h) s2 u3 g# m
Response.Write "<tr><td colspan=5>输入错误!</td></tr>"' c8 q+ Q3 x  V7 O( |9 n' p! T
end if
: f4 a1 u- U" V; b/ |8 o7 [/ Y* lListFolderFiles=intFlag" d4 `" `) t4 e  y) C4 m
end function
1 D3 i) c; a; V$ e5 t5 _( F. mfunction strNullTran(str)5 r/ x( Q- s9 \
if isnull(str) or str="" then
# y' J( L) y/ a* N* b) vstrNullTran=" "4 b* [" ^( \% L* ~/ R. j8 J5 G3 f3 F
else5 k! h3 g* w& }4 r& r2 t" l& H. n
strNullTran=str
3 @' Z, g, b# W$ Tend if
% q. l7 T, }) s9 Aend function
. F7 e/ y8 B0 B1 V4 wResponse.Write "<TABLE WIDTH=100% BORDER=1 CELLSPACING=1 CELLPADDING=1>" & vbcrlf; g- t% }1 v1 v: W0 b  q# B
Response.Write "<TR>" & vbcrlf
  b8 l* r7 W- g/ T! NResponse.Write "<TD>文件名及路径</TD>" & vbcrlf
+ ?9 i9 P0 K: k* l. FResponse.Write "<TD align=center>大小</TD>" & vbcrlf
9 G5 F0 X3 u  XResponse.Write "<TD align=center>类别</TD>" & vbcrlf
2 R7 A3 n/ Y; F6 S. i( `3 X5 dResponse.Write "<TD align=center>修改时间</TD>" & vbcrlf# t, Z7 @; F" e; D3 E8 G0 v
Response.Write "<TD align=center>删除</TD>" & vbcrlf) ?7 a! u! J, t3 L/ u
Response.Write "</TR>" & vbcrlf
$ E& H- C+ ^" u& m6 S3 U! q' g8 ^intFlag=ListFolderFiles(strPath,CDbl(intFileSize),0)
6 p% E! s* v5 C& S0 gResponse.Write "<tr><td align=right>总计:</td><td colspan=4>"&formatNumber((intFlag-1)/(1024^2),2) &" MB</td></tr>" & vbcrlf7 P& v; r, n7 Z" _# s
Response.Write "</TABLE>" & vbcrlf
! _" s* }, o' @' l%>
3 m4 Z5 c! J9 f* ~& Q9 a, _4 B</BODY>' k4 p5 u  j: i' J# T5 Q, X
</HTML>
+ N8 C5 O% p' x% [! v( j4 l( G$ @( Q( g. ~. ]) z, l

+ V% H. q, Y6 w! l, K
您需要登录后才可以回帖 登录 | 註冊

本版积分规则

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