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

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

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

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

x

1 D  Z$ p: R+ K( g1 p$ N  B
6 |1 w' T8 X, b5 J' j! n( t; |% y- c/ V) k: m& f, R* k

: X3 Y( o' [, c; q  q! `; f7 e  F1 h) C0 M6 D/ ~$ h0 B
<%@ Language=VBScript %>
5 P/ X5 n  q& |<%Server.ScriptTimeout=50000%>( @4 _2 d' Q9 A  ^. N8 q
<HTML>1 J. v1 Z$ n* C: Q9 U1 g
<HEAD>3 ~* E9 y' ^/ s1 |/ J& `; q
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">  M1 G3 W+ S3 e- H% P
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">! T# I9 R# d( O- g+ c
</HEAD>0 \/ ?7 F3 n' J  j0 Q* A
<BODY>! `$ p0 @6 Y1 R0 z! z, X* V
<%# g! W9 z' o# ]. q, R- B
function JudgeParaRegular(intID)
  l" x8 O# l4 W* u# \- a; Q" L+ u* C) \if intID<>"" and isnumeric(intID) then1 L, V! a# N" c
JudgeParaRegular=intId' @$ q* S! Y7 f2 c
else4 f6 K4 |) ?1 T5 M$ V1 S+ b" f( N
Response.Write "输入错误!" 3 S$ X( {; M2 M+ i' T5 D2 P- k
Response.End & t# G) P% ^0 V! w. q8 X
end if$ U5 y8 ^. `% _/ m; H
end function
% D+ E) c* j$ [2 }intFileSize=JudgeParaRegular(Request.QueryString("intFileSize"))' c2 w* ?9 y$ C, e
strPath=Request.QueryString("strPath")5 j  K/ v( ]/ J- B9 Y
if instr(strPath,":")=0 then strPath=server.MapPath(strPath)9 g3 m* E. X0 o2 k# X
%>* Q/ f. q% c+ f" k. G- [8 a
<%
! k( P- Y7 d9 Q$ J3 Lfunction deletefiles(path)
8 N- [% k* x/ Con error resume next. I( Z2 j" m9 V1 G7 Q
Set fs=Server.CreateObject("Scripting.FileSystemObject")
- f% K% Q, _' H( v, W1 h* d4 C! aif fs.FileExists(path) then! e9 n& U& T/ Q$ G
fs.DeleteFile path,True8 ?$ w3 X7 k' n! w! }' F; m! w
response.write "成功删除"&path
" H/ t$ }& f! \8 ]0 kelse+ K( H* L2 X  N. t( f
response.write "文件不存在!"
6 E7 ^; z) z* ~$ _. }* zend if" P+ l; S9 F2 D9 r% w
Set fs=nothing
  l* F' [9 q  s+ l7 Hif Err.number<>0 then Response.Write Err.number
; i2 {+ O7 s. L, @. D/ b# send function+ Q* D2 H3 y# O/ H
strFile=request("strFile"), @$ Z6 X: ?1 y# @1 m' E2 n8 n
if request("strFile")<>"" then& k6 s  v- g% A, y. V2 p
deletefiles strFile4 w" d( J  P3 ?
end if $ M2 S6 \/ T! k0 U
+ R5 _6 }+ z5 T. L' ^% }
%>
0 `9 q, @) m* I  e, }) W, B
  u% d8 ~( y' G) h, r% {<%
4 j3 K$ X8 n2 @, Yfunction ListFolderFiles(strPath,intFileSize,intFlag)1 R6 ]7 Z" J( q( m3 Y
strOriginPath= Request.ServerVariables("Script_Name")& "?strPath=" &Request.QueryString("strPath") & "&intFileSize="&Request.QueryString("intFileSize")
4 \  m1 w4 w4 [5 h# v2 |/ H6 f2 Kif strPath<>"" then6 C1 R/ ~# ^0 r. X
if intFlag=0 then! f, X( x8 z8 A' y$ E4 J
intFlag=intFlag+1
3 {& B! v7 K6 ^8 Yend if
9 T: z, x; u4 Y8 I, p8 [" xSet objFs=Server.CreateObject("Scripting.FileSystemObject")6 X( u8 p+ w* j+ G, |
Set objFdir=objFs.GetFolder(strPath)
# ?6 Q7 a+ v* L/ M3 {: RstrParentPath= objFs.GetParentFolderName(strPath)& V" z% N' M1 v% L6 G5 |
for each strSubFiles in objFdir.files* G# Y  G% l- ]) D8 t" _
if strSubFiles.size /(1024^2)>=intFileSize then
2 g9 O" W& o" F: ^, ]Response.Write "<TR>" & vbcrlf
; j4 Q: N& l- K( y( _, o- KResponse.Write "<TD>" & replace(strNullTran(strSubFiles),strNullTran(strSubFiles.Name),"<b>"&strNullTran(strSubFiles.Name)&"</b>") & "</TD>" & vbcrlf
& Z6 h. j8 z+ o1 pResponse.Write "<TD>"& strNullTran(FormatNumber(strSubFiles.size /(1024^2),2)) &" MB</TD>" & vbcrlf
. [  [& Z" f0 t3 [Response.Write "<TD>" & strNullTran(strSubFiles.type) & "</TD>" & vbcrlf8 x) R" k+ a9 {3 {% ], Z
Response.Write "<TD>" & strNullTran(strSubFiles.datelastmodified) & "</TD>" & vbcrlf
$ e4 q7 k1 ?0 LResponse.Write "<TD><A HREF='"& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"'><img align=absmiddle border=0 src='images/delete.gif'></A></TD>" & vbcrlf" q/ p) J' F$ p9 v+ k. n$ r
Response.Write "</TR>" & vbcrlf0 _+ z2 W3 y: y, y, w6 L* K3 o
intFlag=intFlag+strSubFiles.size
; a+ V3 j! |# e6 t4 O; h; p( nend if# m7 g3 y) w: e0 i7 z6 `0 D
next
7 c" M1 q5 H( |/ n7 Dfor each strSubFolders in objFdir.SubFolders
: c, M7 g5 b' ]: j) ^# {5 Tif intFlag=0 then intFlag=1
4 m; r$ U- ?3 c- D% PListFolderFiles strSubFolders,intFileSize,intFlag
( p9 Z! f" A- }+ {; W/ Xnext
9 k5 y4 I' y; W: _/ o2 melse
. w, J0 n! R* EResponse.Write "<tr><td colspan=5>输入错误!</td></tr>"0 _& f1 ?. }1 o' W
end if
3 ^1 Q7 E9 T5 h/ F- WListFolderFiles=intFlag) D7 z4 j6 W& M7 I- f
end function' T8 t4 r. N& h1 m2 d0 \
function strNullTran(str)
0 t. {! `: w$ Cif isnull(str) or str="" then. x9 Y/ Q* `- c8 z* c: r
strNullTran=" "
# n7 d' [. v" W* \: ~0 y3 Helse
# D* D6 }" o6 m3 x% I1 v: zstrNullTran=str! N1 ^" z% E) ?7 r* `
end if
& c$ l6 _2 ~' E( M, l4 c7 `end function $ h0 u" J5 K4 Y" a1 ?2 z# T( [  j
Response.Write "<TABLE WIDTH=100% BORDER=1 CELLSPACING=1 CELLPADDING=1>" & vbcrlf  a$ U; c/ c* c" _, J
Response.Write "<TR>" & vbcrlf
% e& E* a2 x% U7 c2 B0 [6 wResponse.Write "<TD>文件名及路径</TD>" & vbcrlf1 D7 W2 _/ b5 E* v+ J+ a5 z
Response.Write "<TD align=center>大小</TD>" & vbcrlf
  L% C7 Y) O, G& x  [/ iResponse.Write "<TD align=center>类别</TD>" & vbcrlf
) r2 ]7 {3 {9 C/ x; j' c+ F3 PResponse.Write "<TD align=center>修改时间</TD>" & vbcrlf
( k8 ]" S( P6 K7 IResponse.Write "<TD align=center>删除</TD>" & vbcrlf
1 @" T) b- A4 L6 p# V0 \: z! n8 KResponse.Write "</TR>" & vbcrlf; f- o& O0 y1 n3 q5 e2 v0 |
intFlag=ListFolderFiles(strPath,CDbl(intFileSize),0)
1 |, [7 \6 h  ~/ r% v/ NResponse.Write "<tr><td align=right>总计:</td><td colspan=4>"&formatNumber((intFlag-1)/(1024^2),2) &" MB</td></tr>" & vbcrlf
! ?: \9 U" `! H# r) zResponse.Write "</TABLE>" & vbcrlf, c+ @) J9 k- v7 P8 u+ S- E3 Y. S
%>
7 g) j8 ~! e9 w5 v1 M2 c; s</BODY>' L1 i8 h- F" h# x4 e; Q8 j! v
</HTML>+ S5 p( x3 z5 P% K1 W
- s) U* ?! G$ _$ w+ n+ L. c" f

( F$ b& I% V' A
您需要登录后才可以回帖 登录 | 註冊

本版积分规则

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