|
|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
添加个窗体,在窗体上添加几个控件可
8 Z3 g3 P' K1 Y D) e( V& _* d+ ]5 kPrivate Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _+ h/ A$ c: P# c2 t; z. A! R
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
, U' J& g% j* U; O. A0 D ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long; @& N- I5 ]5 C
# Q( r2 N# u) g1 L8 B6 UFunction FindFiles(path As String, SearchStr As String, _0 U; j# k! j( Q% [3 }
FileCount As Integer, DirCount As Integer)/ X; L; {9 @0 D4 G7 u* M
Dim FileName As String ' Walking filename variable.
# G; T+ J) |6 v Dim DirName As String ' SubDirectory Name.
7 n- W+ W! w1 }9 r: A+ H Dim dirNames() As String ' Buffer for directory name entries.3 E5 F/ |& Z% g# @. w7 m
Dim nDir As Integer ' Number of directories in this path.
, y4 D8 j) p0 d, t) G+ F- |) s Dim i As Integer ' For-loop counter." ^+ A: A7 V# ?) e
2 O/ J' ?$ x0 U+ ?' A+ k
On Error GoTo sysFileERR/ E' D8 D- H) y: `5 V8 d
If Right(path, 1) <> "\" Then path = path & "\"
1 m$ F0 Q8 k& ~0 z O$ `7 l ' Search for subdirectories.+ g1 V9 G; T. }3 T, T1 W
nDir = 0
4 X% h/ L/ D+ B1 p ReDim dirNames(nDir)4 W. d. g6 S! Q: k `: ^
DirName = Dir(path, vbDirectory Or vbHidden Or vbArchive Or vbReadOnly _, i3 u* z G0 j0 h; h2 }
Or vbSystem) ' Even if hidden, and so on.( I1 \$ p+ V; H3 d) y! }( N- [( X
Do While Len(DirName) > 02 p; s; c6 E+ ^/ L3 P' G+ c
' Ignore the current and encompassing directories.+ X: ~5 ?9 v. y2 H
If (DirName <> ".") And (DirName <> "..") Then
& ?' v1 W/ H+ W `, c; T ' Check for directory with bitwise comparison.
; k( t8 V t( P( G If GetAttr(path & DirName) And vbDirectory Then
0 B' `9 |% S; D5 m' d dirNames(nDir) = DirName/ g8 A* E: @+ _! d5 Y- P
DirCount = DirCount + 1
& G1 J# z9 u- Z4 f7 x. | nDir = nDir + 1
( ~- x" T8 Y& _ W8 h" Y ReDim Preserve dirNames(nDir)6 n1 r$ Z* w) V) F) z: x
'listbox2.AddItem path & DirName ' Uncomment to listbox" ^" h) t3 |$ c! R5 |
End If ' directories.
3 W- w' k- n4 E% p9 X2 |# r4 NsysFileERRCont:& u! q0 `& d; s
End If" X, x9 g/ R6 i" b7 d* r
DirName = Dir() ' Get next subdirectory.9 D; L2 t0 t0 F4 }3 j' J
Loop
% m) F- B2 T8 s9 d& v+ A; B8 v. ^
' Search through this directory and sum file sizes.9 [1 }0 K3 f+ o+ Y& ^; J
FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _. e4 ` S1 `' g2 Z
Or vbReadOnly Or vbArchive)
4 S7 Q# l! w. u8 y: s! y2 G While Len(FileName) <> 07 b0 b" T4 s8 {& M0 j- O# `" ?: Z
FindFiles = FindFiles + FileLen(path & FileName)4 n, @$ B: K3 J0 S& u
FileCount = FileCount + 1( v9 q F. ]& P" n B- W
' Load listbox box
9 \5 \8 Z8 o1 E ListBox2.AddItem path & FileName '& vbTab & _, w! t7 U" r2 v* }+ b
'FileDateTime(path & FileName) ' Include Modified Date
9 \" u& o$ v9 Z" E6 d" r FileName = Dir() ' Get next file.
: ^5 _2 @, x) m% p7 ]9 G Wend$ s+ O! O# m& {/ \) c1 J1 C8 ]9 w
, h: K6 W/ M1 Y, r" f2 q! \ ' If there are sub-directories.., y4 p) E7 e% K9 a
If nDir > 0 Then* C2 y) C/ Q" j) R9 d
' Recursively walk into them
9 z0 L H8 K. @2 l) A8 b4 E5 K# f For i = 0 To nDir - 1, V( V% `0 J' O" t1 k# _. [- j8 c6 E' E
FindFiles = FindFiles + FindFiles(path & dirNames(i) & "\", _
- b9 r1 Q1 @# [, m4 ^8 C+ s SearchStr, FileCount, DirCount) k; e" j- g- F6 `
Next i' T0 t8 Z3 \! e7 T! `
End If
4 z1 g5 i" Q1 T8 t2 d0 J8 T( G# t. R }8 m
AbortFunction:
; \9 T7 I1 ~+ c; w; r) ` Exit Function
9 a; J. a7 }) Q) D7 [" ssysFileERR:9 {3 L, m. ^5 U+ J
If Right(DirName, 4) = ".sys" Then
9 ?' E+ C& }7 `6 x# F8 E6 b Resume sysFileERRCont ' Known issue with pagefile.sys
/ u0 [! h* W( {3 T) X Else, P; h$ B |# u+ J0 w) A7 M% s
MsgBox "Error: " & Err.Number & " - " & Err.Description, , _# z! p3 A! X) c6 K
"Unexpected Error"
' u7 T, q6 c2 {9 b3 K3 O Resume AbortFunction7 c, a, o/ [6 Y: i- h: p- }3 f$ i
End If1 I2 R+ V- X) q$ {, y! w
End Function
! v- L" }4 V! U$ d$ \% L* j6 z$ ^- ~% O, P4 U1 I3 _, \
Private Sub CommandButton1_Click()2 O( O, U( q$ P& z) W
SearchForm.Hide0 }# n6 K- _; o5 _8 p8 D6 a
End Sub) b! [) h! v' ]8 C# |0 m; Q* Z" J
! Y& C; u6 Q/ p8 b. r Private Sub Commandbutton2_Click()
h8 H9 g. l& T/ b Dim SearchPath As String, FindStr As String
! ~& A) o' @. r6 B& z Dim FileSize As Long; i$ `! p0 ?7 l, z$ Z
Dim NumFiles As Integer, NumDirs As Integer* `) |6 b; A( ~) t3 h
9 y5 ~4 H; r: B1 E8 z6 z# u. l/ c x
'Screen.MousePointer = vbHourglass
7 [4 A$ ~8 h4 B+ n. [6 O; P ListBox2.Clear6 ~2 H9 `3 N$ {5 p# z
SearchPath = TextBox1.Text
; W; z3 ~% J" `# }. _ FindStr = "*" & TextBox2.Text & "*" & TextBox3.Text4 W0 c4 v9 w) Q
FileSize = FindFiles(SearchPath, FindStr, NumFiles, NumDirs)
+ t" p4 r7 q z TextBox5.Text = NumFiles & " Files found in " & NumDirs + 1 & _
5 {) f% F: |3 ~9 h, F " Directories"9 R7 I8 x2 \1 F& d4 ^
'textbox6.Text = "Size of files found under " & SearchPath & " = " & _" U) b' ~: e, o- z$ R7 N4 ]
'Format(FileSize, "#,###,###,##0") & " Bytes"9 t$ a# X8 t4 M+ ~7 v- M! i* Q0 h) J# R
'Screen.MousePointer = vbDefault
+ x; j% ?" j" p If ListBox2.ListCount = 1 Then ListBox2_Click0 o2 W6 I* T) d. S4 E7 S
End Sub
M$ h3 w7 Y9 @, ]% ~
' B" y) y' R- A( V7 u6 z# y
0 Y) \$ [4 v1 N! N1 NPrivate Sub ListBox2_Click()9 @: Y p8 ^1 c+ Z- N
Dim strfilename As String2 s" \3 a7 |* U$ ?6 F
If ListBox2.ListCount >= 1 Then* d3 N4 y* `" t! d
'如果没有选中的内容,用上一次的列表项。
4 i: ~; B' ]& ]5 O7 i4 C. a8 g If ListBox2.ListIndex = -1 Then
" K( O5 x% }$ G( N2 @8 r T ListBox2.ListIndex = _0 g+ S! a) Y1 N! t( E
ListBox2.ListCount - 18 Z5 v+ @4 w R7 f3 O+ l
End If
! D7 J1 X/ E& S, o& _2 \( G( S% I strfilename = ListBox2.List(ListBox2.ListIndex)
2 X* x# Z4 T* }5 s0 t! T# V/ R
; S' d3 \. q, _1 G! i ShellExecute Application.hwnd, "open", strfilename, _" f$ t/ e! C" f% W$ V/ l
vbNullString, vbNullString, 35 M& C/ n& _0 t. T8 h1 [
End If
, _# Z9 V% Y4 q8 i/ D/ O& O& W' o' n% l- C; q H
, z$ T- k `, l9 Z% MEnd Sub. B9 X& x F: }" `# e
0 s7 z3 F# ~, v5 @Public Sub Start(ByVal strfilename As String, ByVal searchfolder As String)
/ E) M U5 P& V5 |* X- P+ lDim sel
3 y3 Z! u: h2 x+ U1 g7 fDim fs9 L u& S/ A# g+ W7 t$ |+ q
CommandButton2.Caption = "SEARCH"( P) V, \1 A2 F
'MsgBox (strfilename)
- q J b0 X- V- v9 }strfilename = Strings.Left(strfilename, 8) '取前八位) G; y& B9 k- t( _
TextBox1.Text = searchfolder
. q8 y0 K, K/ `TextBox2.Text = strfilename
3 z9 F8 O+ b$ v/ x8 ~+ DSearchForm.Show vbModeless
2 g# [2 @6 n0 b# |: M, T
7 ~( x# r* x% V: BIf Strings.Left(strfilename, 2) <> "17" And Strings.Left(strfilename, 2) <> "H7" And Strings.Left(strfilename, 1) <> "S" Then
x5 j0 F% B9 K+ l MsgBox ("Not drawings No.")" V* ]& g+ }! Z; t" ?4 B- \
' ]. ?- [+ g7 e- K4 Z' k
Exit Sub
/ }4 p" l: u! DEnd If
; o$ i4 h# e8 z! e8 ?( z V+ O4 E5 `% N, v( A2 m; p, M
'CommandButton1.Caption = "Use API code"" e# u" P3 X1 ^; Y& m: p- q1 Q8 d
! R# f2 ~* l) ], |. i
' start with some reasonable defaults
1 E) q' ]: ]( t g: Y Commandbutton2_Click
9 m; w% o, r. @7 T/ [4 kEnd Sub |
|