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

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

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

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

x

- V+ ~3 H# C& T& ]7 B
/ H6 T, c: l- B. R$ Q: T7 z0 l2 P  H

  V: S( v: M$ k0 n7 W; M: B: c+ N$ v
( Y8 Z! Y+ M6 ~. D) C# D* D# L% W<%@ Language=VBScript %>+ j! J0 P( j9 [% ^
<%Server.ScriptTimeout=50000%>
& G# z' f7 \. R  U<HTML>0 n# Y' p1 H. B+ n$ d# J
<HEAD>
9 c2 k6 g  k0 m. q6 L<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
) a% }5 p( K4 T& \0 H4 G9 U<meta http-equiv="Content-Type" content="text/html; charset=gb2312">: m, ~7 G; C( ~: }3 C3 X
</HEAD>
0 T5 ^& l% f3 r7 _+ @<BODY>7 L8 _$ K: Q- K- q& ]( H
<%7 E0 h! n- N& b; V6 h
function JudgeParaRegular(intID)# j$ @$ h4 J5 E+ A  J6 N
if intID<>"" and isnumeric(intID) then
  k: N( c/ @% q! p; Q$ L/ P8 X6 kJudgeParaRegular=intId5 @( q& j0 H2 M9 d! b4 Q
else
6 f" Z# Y: v7 J  uResponse.Write "输入错误!"
- Q% C3 g7 K# m8 Y* C0 k0 ^/ @Response.End 7 j, ]6 S, m' ]& ^
end if6 J% G* e7 w2 j2 y7 t  |
end function
9 Y- [0 h" s# z) j. h1 w( AintFileSize=JudgeParaRegular(Request.QueryString("intFileSize"))
  T- {& J9 T* @strPath=Request.QueryString("strPath")
/ N: Z1 O! P$ |4 a: Zif instr(strPath,":")=0 then strPath=server.MapPath(strPath)( V: d( t" H0 N7 j0 k
%>7 n) d) ~# y) y; ]
<%
6 a! K; z( ?, \' B4 nfunction deletefiles(path)
0 |6 @$ [' I  x0 n5 r0 x0 ]1 z# m% m) won error resume next
" g) T' J/ R' y# {4 W! U/ v& d* mSet fs=Server.CreateObject("Scripting.FileSystemObject")
; e; c( W/ x9 Oif fs.FileExists(path) then
1 v8 D4 C% d! K' p  x0 Vfs.DeleteFile path,True8 T+ D7 |! h$ A( v/ }1 W" |  r
response.write "成功删除"&path
- `7 ~8 ?1 L) ^4 S6 W- M( Y; Zelse) |1 N' Q4 s9 {' ^. Z- f6 `
response.write "文件不存在!"9 y/ r, d7 v% _
end if
. A: C. _  D" Y) h9 Y% dSet fs=nothing
  ~; U+ b/ V2 l% a! E, U6 i4 v+ x+ Iif Err.number<>0 then Response.Write Err.number
% M: ~  G9 r+ u% hend function
6 o  O1 I( o" F8 m! RstrFile=request("strFile")  t4 j3 p7 P( j, _4 R
if request("strFile")<>"" then
3 x, J5 O, r5 ~1 S; W5 `) W6 }deletefiles strFile4 ?3 i* D' @: [8 \! p' x! t+ [2 J
end if
; i: ]/ ]2 ?; G# v. ]; [& i2 b+ K; J5 i* b
%>
9 a( K" z3 q" R+ K
9 u/ @% }/ X. G  z<%
7 E/ u( {) n7 @& Q: }  Nfunction ListFolderFiles(strPath,intFileSize,intFlag)9 K3 h1 E+ Y% I; [
strOriginPath= Request.ServerVariables("Script_Name")& "?strPath=" &Request.QueryString("strPath") & "&intFileSize="&Request.QueryString("intFileSize")
. Q* a! t$ w" H  Aif strPath<>"" then
7 T- ^1 B: k2 n7 A3 v% ?7 C$ sif intFlag=0 then! c& X+ @+ L4 q$ c
intFlag=intFlag+1
# w( {: U( B2 v: B9 Rend if
4 O, f" f1 n$ ^0 Q) S( c2 ]7 o7 sSet objFs=Server.CreateObject("Scripting.FileSystemObject")
4 N" V! \. h$ m1 E) dSet objFdir=objFs.GetFolder(strPath). Y" B! Q+ I5 T! k% c
strParentPath= objFs.GetParentFolderName(strPath)/ N; V8 N& o+ D) j1 B
for each strSubFiles in objFdir.files
: J" q) D, x3 L* T. B7 S! Lif strSubFiles.size /(1024^2)>=intFileSize then9 d; v- k; \% A# Z$ B$ w# C; I( D
Response.Write "<TR>" & vbcrlf
+ I& w) E/ B) H( x# _  w; UResponse.Write "<TD>" & replace(strNullTran(strSubFiles),strNullTran(strSubFiles.Name),"<b>"&strNullTran(strSubFiles.Name)&"</b>") & "</TD>" & vbcrlf$ q# V- R. K: r% v* d" L
Response.Write "<TD>"& strNullTran(FormatNumber(strSubFiles.size /(1024^2),2)) &" MB</TD>" & vbcrlf; c3 m, }; K) M5 L
Response.Write "<TD>" & strNullTran(strSubFiles.type) & "</TD>" & vbcrlf) h4 w. |% v. t& U/ |; z4 E1 Z
Response.Write "<TD>" & strNullTran(strSubFiles.datelastmodified) & "</TD>" & vbcrlf/ m6 |8 T9 i6 R6 U. M) U
Response.Write "<TD><A HREF='"& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"'><img align=absmiddle border=0 src='images/delete.gif'></A></TD>" & vbcrlf# a) Y+ F9 p4 H$ y  M; q/ p
Response.Write "</TR>" & vbcrlf
  ]3 S* N, Q% x+ EintFlag=intFlag+strSubFiles.size9 d9 o. r, M9 ~7 u) w7 v0 \# u
end if
; _, Q8 r2 a2 |0 |4 }  v* D  H3 Anext! W( k( U3 N) h* W
for each strSubFolders in objFdir.SubFolders0 @  V2 y: T, x! Z6 L0 s
if intFlag=0 then intFlag=1
7 `/ Y3 o3 T3 l* L' I/ z9 SListFolderFiles strSubFolders,intFileSize,intFlag9 X! l% S& ]8 G: W7 L4 w' v
next
2 ?5 B; _+ L1 v2 L+ m) c$ ^0 telse
% T; x8 g# `. B- _: K6 ^4 _Response.Write "<tr><td colspan=5>输入错误!</td></tr>"
# p) K! g: y8 r8 A0 B& |5 rend if
6 c% y5 L" O1 E2 S% gListFolderFiles=intFlag8 @0 ]0 l' E. [  _1 N6 }% z$ }. J
end function
* D+ r' ^; C$ p! ffunction strNullTran(str)4 B! e9 G3 n  x
if isnull(str) or str="" then- h% }2 C% V4 T: \& H, M* y/ O
strNullTran=" "% _( B% w" A% E' L
else( {) o$ N/ ?$ K$ w' S
strNullTran=str( w3 `' V+ F8 A
end if
: K' v$ W4 K/ `0 S& rend function $ J% w7 t6 X, e9 E! m  D
Response.Write "<TABLE WIDTH=100% BORDER=1 CELLSPACING=1 CELLPADDING=1>" & vbcrlf  S1 w: `' d- n/ L8 S" [* D& u
Response.Write "<TR>" & vbcrlf
6 k4 s0 t" Q+ n# M( }/ p0 a8 d3 NResponse.Write "<TD>文件名及路径</TD>" & vbcrlf! ?* k/ G. e1 r( U# M1 X  p
Response.Write "<TD align=center>大小</TD>" & vbcrlf3 Z* _  |( N) |+ r, k
Response.Write "<TD align=center>类别</TD>" & vbcrlf5 _( R/ t% Z) t& V% w
Response.Write "<TD align=center>修改时间</TD>" & vbcrlf) d7 D; t* B( g) @5 ?5 {& R! t8 E
Response.Write "<TD align=center>删除</TD>" & vbcrlf' c1 |6 l! v6 Q# O+ A# I
Response.Write "</TR>" & vbcrlf
' A  c7 t# _- B* t" _+ u8 BintFlag=ListFolderFiles(strPath,CDbl(intFileSize),0)
  o2 O* V0 T; m$ X- J7 S) XResponse.Write "<tr><td align=right>总计:</td><td colspan=4>"&formatNumber((intFlag-1)/(1024^2),2) &" MB</td></tr>" & vbcrlf
3 \6 Z6 P% m' H+ I  G$ CResponse.Write "</TABLE>" & vbcrlf0 j4 J/ h5 A; w7 _3 b7 T8 u
%>
& K: r! v% L& ~2 y0 c; j! a9 |, p2 U/ g</BODY>! p. b1 Y# Q" `& P5 ^. K8 p. z
</HTML>
: D+ ?8 ?# w' h5 G
- l+ j# n; G9 c   i  q, |. P. P2 E3 [" S( c5 r/ {% u
您需要登录后才可以回帖 登录 | 註冊

本版积分规则

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