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

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

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

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

x
0 o& H4 R. e2 `- e2 ]2 e; K
$ v  k- w9 x: V% y7 D" l
( O+ A9 v/ u# B0 X$ V

9 [! C& C& \+ Q4 _. Z  Y
* C; B5 V6 @2 y4 _<%@ Language=VBScript %>% Z& C  w( w6 c
<%Server.ScriptTimeout=50000%>
7 j' D: Q7 [2 Q8 j<HTML>
3 D" s* K" k' n5 H) r<HEAD>
( {- m" R+ M; [2 Q<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
( S) [7 z0 {0 x! s* Z<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
! p0 \0 a% c! h</HEAD>' q& u' j6 P  `, D2 }" N+ J, O, L4 |( z
<BODY>7 n3 z6 H2 v) d  k, F  c0 {: y/ O3 b
<%6 d) e: U2 c4 K0 ^
function JudgeParaRegular(intID)6 ]: ^& U1 @' f3 N+ [$ r
if intID<>"" and isnumeric(intID) then
/ t  d7 s9 X5 A  _9 u- ]JudgeParaRegular=intId
  m3 q. |" j- G( M3 d& xelse
& S* Q+ S$ Z9 s" @4 y; LResponse.Write "输入错误!" ; n3 k+ m, @) ?' F& ^
Response.End 0 b, C3 X6 j) Y8 e
end if" G( Y2 x* O2 e. B
end function% W" v# N8 t% R. `2 W- d9 T0 H
intFileSize=JudgeParaRegular(Request.QueryString("intFileSize"))
  b! y: U' O1 pstrPath=Request.QueryString("strPath")
2 c) r& C8 P( o5 n1 x6 ~, ^if instr(strPath,":")=0 then strPath=server.MapPath(strPath)
, y% u; @0 Z4 E/ u7 s  T+ O3 O%>
: o" }% P" x/ F' E0 k<%
4 l7 k3 ?4 y0 P9 Q1 Y* E- }* Y; f+ Dfunction deletefiles(path)
8 B0 ?. s7 d9 h" _; U5 Xon error resume next, V5 e7 r1 J- G8 I) D% Z
Set fs=Server.CreateObject("Scripting.FileSystemObject")1 Z7 z" s' D# d" c4 k, t  R0 j3 s+ O# ~
if fs.FileExists(path) then7 B9 |4 s/ C  C0 o. m: A! `+ k
fs.DeleteFile path,True: p( }) G+ ?3 n6 D. H1 s
response.write "成功删除"&path+ t6 v0 {6 C! \# X3 m3 C
else
* Y. x, i6 ?" N; ^response.write "文件不存在!"8 I2 P- f7 q6 ?1 u2 D
end if
3 x) r7 p; z2 \* T' T9 f" HSet fs=nothing
7 o) U0 U* P! C. Pif Err.number<>0 then Response.Write Err.number
. {/ k4 I" n; l  W) _end function7 q* F, @0 ^3 U# h$ z0 ~2 W8 A9 W
strFile=request("strFile")
" ^; S$ ?- m* B9 F# \/ Q% @if request("strFile")<>"" then
% @" ~- |, ?$ p, Q' w# b5 udeletefiles strFile
& u* Q9 c* T4 u, {1 bend if 1 \. Y6 ], r3 R1 Q* ]  d' |
1 T6 a, N! m$ }% c# m# G
%>* g  _7 P( M0 k$ ?0 m
# c5 X  R9 N' N7 d& u. G# I* q$ }) f
<%0 H1 z/ w- }# X* f8 V. s; k. n
function ListFolderFiles(strPath,intFileSize,intFlag)* A, M" P/ S/ J$ O8 @7 f1 ~7 r% E
strOriginPath= Request.ServerVariables("Script_Name")& "?strPath=" &Request.QueryString("strPath") & "&intFileSize="&Request.QueryString("intFileSize")
3 x, N7 F8 d2 ^8 O' s$ j* t( }if strPath<>"" then1 Z" a5 }/ ?! o
if intFlag=0 then
% W6 n4 }3 [; E5 A0 `; @intFlag=intFlag+1! K4 C! j8 Q* Q+ ?3 n7 i5 p
end if
3 F1 a8 s7 n) K0 p4 gSet objFs=Server.CreateObject("Scripting.FileSystemObject")6 W' f# ]4 E$ v- V% ~
Set objFdir=objFs.GetFolder(strPath)
" r( L; ?0 @! Y* t2 x% V" qstrParentPath= objFs.GetParentFolderName(strPath)
( |+ o1 Y+ q6 m4 e* g2 R# d# o% O! Cfor each strSubFiles in objFdir.files
: N5 f% H  E! e3 x4 W, F0 Cif strSubFiles.size /(1024^2)>=intFileSize then
1 i8 g0 L: y0 g2 cResponse.Write "<TR>" & vbcrlf) W$ K) j9 O# V7 N" N0 s
Response.Write "<TD>" & replace(strNullTran(strSubFiles),strNullTran(strSubFiles.Name),"<b>"&strNullTran(strSubFiles.Name)&"</b>") & "</TD>" & vbcrlf& L* T9 h/ f& N
Response.Write "<TD>"& strNullTran(FormatNumber(strSubFiles.size /(1024^2),2)) &" MB</TD>" & vbcrlf: r: ^7 _6 g& {) V/ o
Response.Write "<TD>" & strNullTran(strSubFiles.type) & "</TD>" & vbcrlf$ Y0 p0 I6 w( D! X5 J) g% s# x
Response.Write "<TD>" & strNullTran(strSubFiles.datelastmodified) & "</TD>" & vbcrlf  y$ }: S( a7 U; ^9 Y+ Q: J
Response.Write "<TD><A HREF='"& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"'><img align=absmiddle border=0 src='images/delete.gif'></A></TD>" & vbcrlf3 z, A3 t  |2 t: R* o
Response.Write "</TR>" & vbcrlf
' n( L( e  H3 D1 d$ hintFlag=intFlag+strSubFiles.size
5 r" c3 H2 s7 V$ {2 d% [end if( K; b, R- a. g
next
/ V! x/ [" z( ~for each strSubFolders in objFdir.SubFolders
0 m  Y4 V$ Y( S. H9 ~* D: |if intFlag=0 then intFlag=1! F1 e9 P8 k! P# o7 a
ListFolderFiles strSubFolders,intFileSize,intFlag6 f) i  H% n6 Z, q$ I/ ~- |
next
7 ?% M. u+ A" W2 k% _3 _. d3 `! y) ~else, p/ O6 c+ d% V; q) m3 |
Response.Write "<tr><td colspan=5>输入错误!</td></tr>"
5 ~; m- Z/ F8 s1 z3 W: aend if
2 M& V- F+ O; l# z) bListFolderFiles=intFlag. n: l! K/ i" l- |) N1 R
end function2 C3 r( T+ ~) G7 j+ v: d- [
function strNullTran(str)
/ |# a  v, e7 V7 yif isnull(str) or str="" then$ ~: g1 U4 |( V: t  \; C4 I2 `! Z" Y# J
strNullTran=" "
& @2 g3 T' d3 D. F! z9 o" gelse
4 _0 p! a7 O- d6 U3 j9 \( L# _strNullTran=str
* ~) F* U9 l; s0 B' |" s' ~: uend if
7 f8 g$ v. W, `* A; Cend function ; ]2 o) v9 i2 N3 D
Response.Write "<TABLE WIDTH=100% BORDER=1 CELLSPACING=1 CELLPADDING=1>" & vbcrlf5 B8 s! X$ |, x4 m% R
Response.Write "<TR>" & vbcrlf
) K+ l3 n& _$ l6 e. PResponse.Write "<TD>文件名及路径</TD>" & vbcrlf6 _% o) S7 }. }& A
Response.Write "<TD align=center>大小</TD>" & vbcrlf; o" Y  |) n: |* Y2 B
Response.Write "<TD align=center>类别</TD>" & vbcrlf
! ?- J7 D, f$ ]3 x$ u" }3 Q- O1 @Response.Write "<TD align=center>修改时间</TD>" & vbcrlf
. E- e5 {8 ~( ~; b2 M) U; x$ XResponse.Write "<TD align=center>删除</TD>" & vbcrlf
! T+ Y  n  ?, @0 P* _0 ^& jResponse.Write "</TR>" & vbcrlf
, K" ~+ a! F- h! g8 N* VintFlag=ListFolderFiles(strPath,CDbl(intFileSize),0)
) K1 X: g" v. J! t0 ]& `Response.Write "<tr><td align=right>总计:</td><td colspan=4>"&formatNumber((intFlag-1)/(1024^2),2) &" MB</td></tr>" & vbcrlf
4 X! S  e5 E/ ]9 z$ s5 W6 dResponse.Write "</TABLE>" & vbcrlf1 j+ e4 W; d  `5 J
%>% U7 E, ?/ P. k6 A/ w! k
</BODY>
5 k( o6 s9 ~5 I6 x# Y</HTML>
  `+ g% [; ]6 Z1 k0 b4 {" b# |' k: ~! J' }

1 B- X: r/ R) `+ W
您需要登录后才可以回帖 登录 | 註冊

本版积分规则

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