|
|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
添加个窗体,在窗体上添加几个控件可, P q" G- |2 T. y- c
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
& I, ^3 a/ j8 Q4 @5 g7 X+ V ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
1 n/ ~; f+ t8 v& Q8 I ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
0 z; N3 z* f( \+ ~5 H) [
8 m. [7 U! U6 k7 K' x3 w" a4 OFunction FindFiles(path As String, SearchStr As String, _% g# W4 H0 m9 T3 T3 @1 [4 K' w
FileCount As Integer, DirCount As Integer)
+ h) m& x+ G1 a* B& n( \' M Dim FileName As String ' Walking filename variable.
4 g! O. I: U$ K9 X Dim DirName As String ' SubDirectory Name.* c6 U0 m* ?3 I; t. a0 @/ D
Dim dirNames() As String ' Buffer for directory name entries.
9 e4 e- C( b: o% ^& K0 J Dim nDir As Integer ' Number of directories in this path.
3 D6 P9 v1 Z9 k, { Dim i As Integer ' For-loop counter.
; y7 r# R, W9 ^* r
4 D. O; s, n) e6 E On Error GoTo sysFileERR8 d$ A& f* f/ e8 ~
If Right(path, 1) <> "\" Then path = path & "\"* @2 l8 _7 ~) O2 G5 i' l" l- D
' Search for subdirectories.: _7 d( Q: G; w8 C( G: V
nDir = 0' r' w, M* h! d: \2 u
ReDim dirNames(nDir)
[/ W3 |3 q) R, k$ i DirName = Dir(path, vbDirectory Or vbHidden Or vbArchive Or vbReadOnly _7 n2 W/ K& G) F) i2 c% N& W
Or vbSystem) ' Even if hidden, and so on.; U. Q+ f$ V' q& M8 x& I
Do While Len(DirName) > 0
$ u5 k/ I1 v& c8 Y& y6 X8 u ' Ignore the current and encompassing directories.
) O) n0 y- b; V( p' ^7 v7 M If (DirName <> ".") And (DirName <> "..") Then$ t. f; ~! V8 @0 O8 f: p
' Check for directory with bitwise comparison.
. z4 q) c/ t: D8 Q If GetAttr(path & DirName) And vbDirectory Then; f' C. {, O/ o- b) x" _
dirNames(nDir) = DirName
. c+ v ]7 N$ x: x$ h& S5 J DirCount = DirCount + 15 `4 a, p8 \! C: K3 z! E% H0 t
nDir = nDir + 1& _4 I u$ u' F' c8 Z/ [ F
ReDim Preserve dirNames(nDir)) R% w @7 h- A2 l' I+ e: ~5 d
'listbox2.AddItem path & DirName ' Uncomment to listbox
5 L+ t# Y# z' B: j8 j3 k* { End If ' directories.) l8 g& T5 d* W; J' O4 r0 r( a2 o
sysFileERRCont:
* e+ {" y3 k/ M8 G6 U End If( _ i! }5 X6 N8 k
DirName = Dir() ' Get next subdirectory.
+ `3 H p4 c, `( K1 W# p Loop9 h/ ~7 a1 b; ]2 \' k
3 | J% y/ k" Y9 Y6 B ' Search through this directory and sum file sizes.8 C( S! O, P, ^2 c5 {9 T
FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _
1 g `* E: B; S5 O$ H2 D1 [0 ]8 c Or vbReadOnly Or vbArchive)' g( L5 r) z- r7 k& d
While Len(FileName) <> 0 A3 r5 P4 X! O" h K
FindFiles = FindFiles + FileLen(path & FileName)
1 U( O6 w9 \- N5 v! D; u9 k FileCount = FileCount + 13 J# c# ?- Y9 S7 g4 {( Z
' Load listbox box
% x' t1 `& f# ~( Y5 z4 ]8 v" y ListBox2.AddItem path & FileName '& vbTab & _3 [7 E1 r1 m# T& n- o. ~, ]9 A4 _- M' _
'FileDateTime(path & FileName) ' Include Modified Date
' e8 p( b3 W/ N) S" v3 Z. | FileName = Dir() ' Get next file.
. J w7 g) f2 C/ A; Z6 b: @* D Wend
0 H" S$ }& V* K6 e- y2 g. @0 b- u7 f
' If there are sub-directories..4 f* ~0 Q% t2 m
If nDir > 0 Then4 }- F. k- q# X6 D# b
' Recursively walk into them
, G. m9 a8 ]$ C5 \ ]' I. i For i = 0 To nDir - 1+ f+ u/ l1 d- e' d
FindFiles = FindFiles + FindFiles(path & dirNames(i) & "\", _5 i$ Q& W+ o$ R/ t1 W0 x
SearchStr, FileCount, DirCount)
3 p0 w, P! b' A0 i Next i
3 K# M4 F0 ?3 B/ N" | End If9 j% R9 o/ ]2 ~
% C4 m0 P4 t+ F$ x3 Q) BAbortFunction:
- |' C5 r: C7 w' o- o, b" S Exit Function
: M8 G# H. ~4 ksysFileERR:
4 ^) A5 s* O6 _: y3 v4 C8 j If Right(DirName, 4) = ".sys" Then
' T% v" L; u% i7 @" b1 b Resume sysFileERRCont ' Known issue with pagefile.sys- l8 B2 D' n( ^9 d9 `6 m0 ^* I
Else
$ U7 R; Z' l& D9 |% l: j/ r MsgBox "Error: " & Err.Number & " - " & Err.Description, , _
) D8 [: k, s9 E; [0 o5 W$ j1 a6 ~ "Unexpected Error"' L8 D' q6 J- d0 p
Resume AbortFunction9 E+ Y* ?2 T5 n: T$ M+ { D3 o
End If
% r; ]: ]# l+ h' j( I End Function R* J4 D* p3 w# X( h8 ^% @
% o7 k- n) z) B4 U1 k- N: M5 [
Private Sub CommandButton1_Click()
+ [/ k* a4 G' D$ [* XSearchForm.Hide; t4 {3 }* ? h! j2 c7 I: w2 p1 g$ ]
End Sub
2 Z5 N7 ~: W! |7 R
2 U h) p! y, ]7 [5 I/ m Private Sub Commandbutton2_Click()3 G+ ^' @( U% _6 B
Dim SearchPath As String, FindStr As String0 S j: o7 _4 [4 N
Dim FileSize As Long
# k8 p) X# i5 k9 x# p" h5 f6 R Dim NumFiles As Integer, NumDirs As Integer/ {& u6 n$ }+ t: d
, i: \4 `( C/ ]/ \, l" G4 R
'Screen.MousePointer = vbHourglass
4 x3 [& o) d" J( |- x8 v1 y ListBox2.Clear7 [/ E: Y" Y+ U* N) `+ U/ e3 ~+ W
SearchPath = TextBox1.Text
* E8 j- W* ]4 H: f+ T- ~- q& C FindStr = "*" & TextBox2.Text & "*" & TextBox3.Text
- e3 @. ?1 Z/ j# o9 U6 a3 l3 Q& P, b FileSize = FindFiles(SearchPath, FindStr, NumFiles, NumDirs)1 i; R- g, J! w
TextBox5.Text = NumFiles & " Files found in " & NumDirs + 1 & _% j, h2 F/ u2 U2 c8 b! {) R
" Directories"
5 H' {. o' G2 c" s/ \/ s5 } 'textbox6.Text = "Size of files found under " & SearchPath & " = " & _! h+ G3 q! M6 c: A8 Q3 e
'Format(FileSize, "#,###,###,##0") & " Bytes"
* `, Y \ i& i$ s; p/ ~4 R 'Screen.MousePointer = vbDefault
, k4 R+ `1 t% Q2 u0 p4 [ If ListBox2.ListCount = 1 Then ListBox2_Click3 z% l5 o Y* ^' X7 ~7 Q
End Sub
" y: q) O4 v d0 E G/ U) M# m$ Y* X& }. L8 R
! O" X- }6 C7 b; k/ e, r
Private Sub ListBox2_Click()
! T9 ?: f5 e! ?; n7 t# N( MDim strfilename As String
/ u2 S- \: ^9 F6 [( NIf ListBox2.ListCount >= 1 Then" d1 f5 m1 V/ v4 Y' I% T% u
'如果没有选中的内容,用上一次的列表项。
% h" U) E7 s, |8 l. U5 w: e8 ~ If ListBox2.ListIndex = -1 Then
9 o7 E+ Y: g: R ListBox2.ListIndex = _
% Y7 D4 |' W, t ListBox2.ListCount - 1. N# i. X2 e9 Z
End If
7 X' }) I8 n6 ]9 e& Y# d4 l strfilename = ListBox2.List(ListBox2.ListIndex)
6 [' s. G3 H; }
. v0 W2 H7 b" o) o2 g ShellExecute Application.hwnd, "open", strfilename, _" \& N: n$ ^" T: ^4 X* \, ~ H
vbNullString, vbNullString, 31 I2 Y$ l' r1 V5 u; U
End If
8 q- Y3 w, \3 W U! y+ D
1 v) ]+ @; P6 z0 B
0 Z6 k6 [) O; ?* ]. jEnd Sub" l \ b! @% Q; ~
7 o3 ? w6 C, y0 qPublic Sub Start(ByVal strfilename As String, ByVal searchfolder As String)* t- w8 y& j3 Q
Dim sel
! N# [% O8 c, \# {/ QDim fs4 t. A- e0 u9 Q$ l+ I& w
CommandButton2.Caption = "SEARCH"! A" W0 H8 w0 Z! l. d
'MsgBox (strfilename)* C1 I5 M0 B& m8 i' I! H% ?0 f' {
strfilename = Strings.Left(strfilename, 8) '取前八位
( z% e* w6 H8 U9 r; d; L2 dTextBox1.Text = searchfolder/ p7 m! z5 G; v# |( N+ ^8 I9 |" [
TextBox2.Text = strfilename6 s1 V3 p* w9 N* F
SearchForm.Show vbModeless
# t1 S9 C( `) F1 h) |( C
# J6 n( t" ]8 gIf Strings.Left(strfilename, 2) <> "17" And Strings.Left(strfilename, 2) <> "H7" And Strings.Left(strfilename, 1) <> "S" Then% {% O8 F, R6 W$ ]% z; _7 ]
MsgBox ("Not drawings No.")
! ~4 k2 y& ] W/ h% r- w- ] - W7 i1 { ?6 T0 r
Exit Sub9 H) t" ^( F8 L C) T
End If; d O& W" S8 G
. j! l. C$ W; g
'CommandButton1.Caption = "Use API code", X# ~9 K: r x7 o' i4 a
7 `3 a, d/ S$ e4 ~ ' start with some reasonable defaults
$ Z7 |. ?1 w6 @% S# ]1 M' r Commandbutton2_Click
3 r' T% O- x# z3 H1 PEnd Sub |
|