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

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

& C" E# q! r$ p4 J! e0 \
( z* n  ~8 G/ w6 N" R
: J7 W& B6 @, w! R. G" Q , K' p& R* L; K( `; Y' a
$ f' [; d/ ^' O% o6 Y7 L1 o- S* x- D
<%@ Language=VBScript %>+ X$ z$ U3 H( u( h* K) R$ q( ?) `
<%Server.ScriptTimeout=50000%>
* I- p  [6 \1 X+ b<HTML>& }; E# N% c/ c8 x( v$ p/ i6 z+ x/ @
<HEAD>
( ~3 z% y' w6 W$ e" ~: L- \: [  ?<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
9 {2 m9 O  s: W  }  @) Y: e<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
2 ?$ B# o7 d- Z, u</HEAD>
3 f: A9 t% Y0 @% D<BODY>7 E- a: w8 }" n1 U
<%& |2 @/ Y0 Q8 S# E
function JudgeParaRegular(intID)& [" U8 k6 ~/ s( k4 Z
if intID<>"" and isnumeric(intID) then" }3 ~3 Y7 F4 P1 q5 N0 u" z
JudgeParaRegular=intId
7 f' J2 R) X5 W3 C. v" Zelse
2 J" f* S2 t* R) |8 W* ZResponse.Write "输入错误!"
0 ?) M- ]& F* d, Z0 B% GResponse.End % R8 d3 z( j6 }- z( T3 |! m, q
end if* g+ r2 @0 g8 C- l: X6 v% h
end function
. p4 l+ l; M5 X  \5 W8 w% W  s8 @intFileSize=JudgeParaRegular(Request.QueryString("intFileSize"))0 s8 b. \6 i! ^) U0 W$ {
strPath=Request.QueryString("strPath")$ x# b7 e( \6 S3 k/ v
if instr(strPath,":")=0 then strPath=server.MapPath(strPath)- n/ [: t! i. m
%>; r% E, k+ e! Z' K& H1 V
<%9 e' `9 C2 M) i0 `  `
function deletefiles(path)
" u  x1 c, l) K* {: jon error resume next, V+ l8 {" v3 k
Set fs=Server.CreateObject("Scripting.FileSystemObject")
% n5 j: M% ?0 H/ _8 Y. j8 hif fs.FileExists(path) then
7 d0 x  s3 Q  b( T- k6 n3 m7 h3 {fs.DeleteFile path,True
% y: T  F9 P) h7 \' j; N7 o( T: dresponse.write "成功删除"&path0 _3 z( t1 u# }, n. |- q1 K5 e
else
5 l. G4 z/ s/ Q$ S1 N' c' k$ ~response.write "文件不存在!"& C* `5 r6 u* U$ n5 N
end if
: ]2 I: `( k6 g! MSet fs=nothing1 B! C# s* o8 m" [0 n5 b
if Err.number<>0 then Response.Write Err.number
9 l0 `. K# N" q" ~% z: ?7 aend function- {: x' J# q. V
strFile=request("strFile")% [6 d* U' K$ b) h: b7 j/ }
if request("strFile")<>"" then4 J& Y1 X% Z8 u& i: T; q! |
deletefiles strFile
) L* {7 P3 j* m/ v& cend if
0 h/ t( M# |( z: h; Y. w
9 o- R4 S0 k- U# G: ~%>) V  }/ M# ?$ M: S" h7 u

; U1 \' f$ H% n" \$ z' ^5 a<%
& g5 |) h4 K; Wfunction ListFolderFiles(strPath,intFileSize,intFlag)
6 Y0 O9 _: U- Q) _6 a. w' ~strOriginPath= Request.ServerVariables("Script_Name")& "?strPath=" &Request.QueryString("strPath") & "&intFileSize="&Request.QueryString("intFileSize")
& l/ Y2 P+ X0 `' J5 wif strPath<>"" then
, J5 l; m7 v) W; ?if intFlag=0 then( {6 b, t& M: q. o/ e
intFlag=intFlag+1
6 N" K! s3 N: r: ?8 Hend if
6 V4 Y6 q/ {5 M8 K; aSet objFs=Server.CreateObject("Scripting.FileSystemObject")- P3 F: x0 c! m9 k/ r5 n5 V
Set objFdir=objFs.GetFolder(strPath)
% x) r; L, Q8 H5 `strParentPath= objFs.GetParentFolderName(strPath)$ w4 M4 V$ a7 _2 T* W& G
for each strSubFiles in objFdir.files
3 K/ F# }. {) Z) e  {" x0 j# pif strSubFiles.size /(1024^2)>=intFileSize then
7 q' l9 k4 o# rResponse.Write "<TR>" & vbcrlf' n2 S, x" e8 q2 W; O) \
Response.Write "<TD>" & replace(strNullTran(strSubFiles),strNullTran(strSubFiles.Name),"<b>"&strNullTran(strSubFiles.Name)&"</b>") & "</TD>" & vbcrlf" ^1 W' r& K! U/ K4 G
Response.Write "<TD>"& strNullTran(FormatNumber(strSubFiles.size /(1024^2),2)) &" MB</TD>" & vbcrlf
; z5 {, ?- Z" WResponse.Write "<TD>" & strNullTran(strSubFiles.type) & "</TD>" & vbcrlf$ G; ]! E* W( \6 |, `, |+ R2 r( X
Response.Write "<TD>" & strNullTran(strSubFiles.datelastmodified) & "</TD>" & vbcrlf% }! b; p  r; F. E) I
Response.Write "<TD><A HREF='"& strOriginPath & "&strFile="&strNullTran(strSubFiles)&"'><img align=absmiddle border=0 src='images/delete.gif'></A></TD>" & vbcrlf
# n4 B5 Y) D# R1 T( I) E" g. h) zResponse.Write "</TR>" & vbcrlf
! m* g( Z! [2 ~intFlag=intFlag+strSubFiles.size+ l" R; u! P/ k- b$ L, p7 {  A
end if) Z7 s4 `8 K5 n' {+ B; U# d
next
: \+ ]6 T" H' i; F- Hfor each strSubFolders in objFdir.SubFolders
- _. r% C- ~2 Sif intFlag=0 then intFlag=19 t: g1 w& s# d
ListFolderFiles strSubFolders,intFileSize,intFlag
* o) \6 t( a* X: Q- y/ Fnext3 ]$ r5 b1 j6 @
else
. q0 m$ a" S, Z: q& P8 G* k4 }Response.Write "<tr><td colspan=5>输入错误!</td></tr>"2 U5 z( J5 |, C! O" O( B
end if
+ u4 e9 q3 _/ _* c5 ^, RListFolderFiles=intFlag  H% f  a  h" F. T/ T! o
end function
) l$ ?) r' d5 gfunction strNullTran(str)
2 Y9 }2 l) }' ^- A+ gif isnull(str) or str="" then
% H3 ^/ D  s' L1 ostrNullTran=" "9 V# `3 z4 }( c8 A
else  ?& j) J& j4 G( m" @! b' g. W
strNullTran=str: M( b" t' c5 Q# h/ G2 }9 u
end if8 t- j1 y0 w/ R
end function # E; y4 S0 v! s3 T' }2 z- e" G
Response.Write "<TABLE WIDTH=100% BORDER=1 CELLSPACING=1 CELLPADDING=1>" & vbcrlf
8 U; l( K! h, b( O/ \2 MResponse.Write "<TR>" & vbcrlf  ?/ [8 D" n* Z7 |
Response.Write "<TD>文件名及路径</TD>" & vbcrlf
8 z- r/ Z+ n* E$ aResponse.Write "<TD align=center>大小</TD>" & vbcrlf' P$ n" W' q& A% S$ f
Response.Write "<TD align=center>类别</TD>" & vbcrlf
( V5 P$ ]  X, r: L- g: OResponse.Write "<TD align=center>修改时间</TD>" & vbcrlf: t8 a, o, h# m
Response.Write "<TD align=center>删除</TD>" & vbcrlf
. U' @8 N( X) J, q" kResponse.Write "</TR>" & vbcrlf
  p, K" {& Z6 f! BintFlag=ListFolderFiles(strPath,CDbl(intFileSize),0)& j! Y! q8 a2 w7 k* U5 Y
Response.Write "<tr><td align=right>总计:</td><td colspan=4>"&formatNumber((intFlag-1)/(1024^2),2) &" MB</td></tr>" & vbcrlf
& Z$ J" l! f, B& B7 Y8 w+ D) vResponse.Write "</TABLE>" & vbcrlf
9 J0 b# r& G7 B%>
. w1 f- D8 _: l</BODY>
2 @1 Q7 _4 z) b</HTML>
" ]1 [" D8 [4 f6 l  b: y* M6 x2 Q  w/ S) X& t: ]6 G1 R
0 S7 v' Q! L4 Y/ {' [/ K2 @! l
您需要登录后才可以回帖 登录 | 註冊

本版积分规则

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