|
|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
添加个窗体,在窗体上添加几个控件可
& Y( p* c4 H) O) {" L# X2 fPrivate Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _, L! _8 C4 s/ S0 t: |% E
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
! i1 L1 L9 P* g1 W: ]. Y ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long6 m; j% o' n7 @6 M7 `
/ Q( ~9 E' E5 r: K" }Function FindFiles(path As String, SearchStr As String, _
0 K2 w) C! C7 W2 ]$ Q- Z FileCount As Integer, DirCount As Integer)/ C! k2 r# `: ]
Dim FileName As String ' Walking filename variable.
$ R" J1 u( Z. q+ Z6 h' x$ l, [ Dim DirName As String ' SubDirectory Name.
" Y, n& _& T' g8 ~! t Dim dirNames() As String ' Buffer for directory name entries.9 i E6 c `4 r, Z% V' a
Dim nDir As Integer ' Number of directories in this path.
2 V: S4 W6 R5 C2 u0 @% m/ d Dim i As Integer ' For-loop counter.* e3 l8 `" z0 p
6 y8 `" P! ?5 ?. Q! ]8 c: O On Error GoTo sysFileERR
O7 q' O1 N: s! y; U If Right(path, 1) <> "\" Then path = path & "\"
! y% a. g# ]. h) L6 p' h) T ' Search for subdirectories.
* y1 D2 h* w' ~; w+ G( }' t nDir = 07 I. Y3 x! R* I2 L
ReDim dirNames(nDir)
& ~9 X! a* o: f" y/ r DirName = Dir(path, vbDirectory Or vbHidden Or vbArchive Or vbReadOnly _% i4 C* c! Y+ [$ R
Or vbSystem) ' Even if hidden, and so on.2 K( `- w# ?! j" {1 b2 p q
Do While Len(DirName) > 0* a& ^0 _# H4 d+ b- J
' Ignore the current and encompassing directories.
& d. z0 ]/ Z g. u: M If (DirName <> ".") And (DirName <> "..") Then: I( @1 _- e7 A) |9 ?
' Check for directory with bitwise comparison.0 _. @; O r$ _
If GetAttr(path & DirName) And vbDirectory Then
+ n* v/ E6 }( L* i3 s5 y J4 v dirNames(nDir) = DirName0 A% N( F) U3 ~( f; M/ g* K1 Q
DirCount = DirCount + 1: f: G/ e! c! e# @* ]
nDir = nDir + 1
: z8 c) D/ K- e: @1 \: {8 d ReDim Preserve dirNames(nDir)
) g4 q$ W+ n) K$ z 'listbox2.AddItem path & DirName ' Uncomment to listbox
# ?1 C& w7 h- t. z8 | End If ' directories." d* W* c7 O( f! n
sysFileERRCont:1 D: W* Y$ I! ~; V% z! F* T! ?
End If/ E; p' ~1 w1 K [. j' L
DirName = Dir() ' Get next subdirectory.
" ^: T, Z% m/ }. `4 ^( t# F) n Loop6 d- V' t5 J; v
3 _' w' M! E' Y" M* a7 i; A, i ' Search through this directory and sum file sizes.
; X/ E, ?6 W. h# N FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _
: Q, k4 B7 e6 T. F3 Y Or vbReadOnly Or vbArchive)$ ` R6 v7 y. n( u" E
While Len(FileName) <> 02 w8 j ] G6 h0 I& Z
FindFiles = FindFiles + FileLen(path & FileName)
; K. b% b+ n/ S9 B. S FileCount = FileCount + 19 E2 ^$ a- ^; c) K0 B/ T( R
' Load listbox box
3 M% U- M3 z1 o% p4 b/ ]0 j( { ListBox2.AddItem path & FileName '& vbTab & _
' N$ E e0 h/ E 'FileDateTime(path & FileName) ' Include Modified Date
& |! w$ Y) C# U$ ?1 n' p# e& Y FileName = Dir() ' Get next file.
. o9 d, n9 x7 K Wend
9 N- Q) T! i2 B% r
! i8 _- E* A/ X ' If there are sub-directories.., |7 F" b. ^& d* c" E$ K; o4 x
If nDir > 0 Then
; |2 c, [* Z$ c4 L5 q ' Recursively walk into them
! ]* N) V* K* Y5 g) U1 f) a& F For i = 0 To nDir - 1% g& F' \2 g3 g( X+ v& \; a
FindFiles = FindFiles + FindFiles(path & dirNames(i) & "\", _6 i! K/ x1 E; Q x8 L
SearchStr, FileCount, DirCount). m4 P+ W: i; ~5 |4 |
Next i
+ b2 ~3 g) ~ G3 G9 t/ O End If
% k. `9 f. h! `3 S" b7 s! j; A' X- J7 U5 k
AbortFunction:: Z- u; g" b, k4 R) a1 ]2 K% x& }
Exit Function! C Z* {, v3 ]
sysFileERR:
, O! O, H( b' c0 }# n0 X If Right(DirName, 4) = ".sys" Then
+ b% M7 g3 x: j Resume sysFileERRCont ' Known issue with pagefile.sys& B% N2 M3 v. v8 {5 T" {1 u
Else6 o7 p) T! T) D; l
MsgBox "Error: " & Err.Number & " - " & Err.Description, , _0 n: | o( B: P1 t" R& x
"Unexpected Error"
! q4 }. o% F6 Q+ @' P# j Resume AbortFunction
0 `- o, x/ ?0 R% { End If
& L1 Y9 U# \1 w# A9 O! u! v End Function
4 H3 a; _; o" T9 ]. z/ r, a% h! K; `% Q
Private Sub CommandButton1_Click()
4 p5 x7 J8 W v3 w7 N M9 fSearchForm.Hide. g6 N4 A8 \) P4 T. N' O& a
End Sub
& a$ E+ S6 r) n4 W# E
# e0 v! t( P9 P5 F3 A3 M+ e Private Sub Commandbutton2_Click()
+ z" b( G R4 V Dim SearchPath As String, FindStr As String
- x; ^! M. K: `; \! Z Dim FileSize As Long
3 U6 `1 P3 m6 G) K Dim NumFiles As Integer, NumDirs As Integer0 B( K) T# z( X3 l& C1 O4 M. W1 r6 D
1 |; U- n0 T! x1 Z! [
'Screen.MousePointer = vbHourglass3 H" A) g3 P5 c3 R- }. i
ListBox2.Clear. W5 P! i6 K, B. _& `
SearchPath = TextBox1.Text/ g. @* R7 ?6 |4 h% X% p0 c
FindStr = "*" & TextBox2.Text & "*" & TextBox3.Text
) B W" }3 a/ B, M6 U2 l) ` FileSize = FindFiles(SearchPath, FindStr, NumFiles, NumDirs)
6 }( }) T# j8 \7 r TextBox5.Text = NumFiles & " Files found in " & NumDirs + 1 & _8 l, B/ W* s7 _ [. ?
" Directories"# m" f7 O d9 O2 n9 ]
'textbox6.Text = "Size of files found under " & SearchPath & " = " & _
( A/ Z- g' d- g/ m- k1 H 'Format(FileSize, "#,###,###,##0") & " Bytes". l( b, g( ^+ o. G
'Screen.MousePointer = vbDefault' r! A; Y i8 D% l' I9 [0 E
If ListBox2.ListCount = 1 Then ListBox2_Click& b0 V' T6 z/ P" N0 E1 }- n/ M- F
End Sub) C2 g0 ]+ ?0 T, z. B0 t
2 b' ~' Q8 e2 T9 a0 d- L, l/ x
9 N4 b# j4 [8 {2 N" [9 y9 y6 |Private Sub ListBox2_Click()5 F' v7 U# G( n% k8 Y- b; Q" V9 h" m
Dim strfilename As String
, u+ C. j9 W* a" wIf ListBox2.ListCount >= 1 Then2 X, z5 \) ]" }& N5 i
'如果没有选中的内容,用上一次的列表项。' {+ e; W5 m8 `$ v1 m
If ListBox2.ListIndex = -1 Then
& f% x# M# D1 N5 n$ Q$ ? ListBox2.ListIndex = _
" g5 x1 v3 G" G( A# P& t ListBox2.ListCount - 1
. Z0 g9 p! ?/ G; `! ] T( B* |! L End If
- f, W7 p- k- g( W strfilename = ListBox2.List(ListBox2.ListIndex), H5 o) v# m8 j. T3 C' m5 F/ @) W5 e
, R) ~4 i/ I1 E) Z& N a0 C ShellExecute Application.hwnd, "open", strfilename, _
# x2 P1 t( r7 L8 n; N5 m vbNullString, vbNullString, 3) v" W) l# y8 f% D- _
End If
5 W7 v% V* Y: c2 l' C3 [6 Y: P
' z0 R( B' g- `. ^8 L {
1 P8 J. n q$ A% u( dEnd Sub3 A. o C$ }3 q5 H! V
0 _5 D! B1 ~0 qPublic Sub Start(ByVal strfilename As String, ByVal searchfolder As String)3 G" G8 J) f$ d4 \$ x3 j
Dim sel
& B5 Q$ D! B* [0 VDim fs; ~6 U# k! V9 M/ @+ h
CommandButton2.Caption = "SEARCH"
2 {! e- V* s7 j' h% c4 ?7 Z'MsgBox (strfilename)) `% i9 `! z( h5 V, R; ^
strfilename = Strings.Left(strfilename, 8) '取前八位9 {* }8 M- w6 T. R4 N
TextBox1.Text = searchfolder
6 G2 Z! s4 R3 @TextBox2.Text = strfilename5 q' s! S) _$ Q* B4 D8 B
SearchForm.Show vbModeless
& l, e$ j1 }. N( l5 e& ]% H7 g2 M. E/ l' `
If Strings.Left(strfilename, 2) <> "17" And Strings.Left(strfilename, 2) <> "H7" And Strings.Left(strfilename, 1) <> "S" Then
) A( _# q9 _! |( d& P; [ MsgBox ("Not drawings No.")
. G' p E/ l9 c% u + t# ^* @7 t9 l
Exit Sub( Q2 k" |0 l9 K1 B$ `4 [, }0 _& N; I
End If
4 o: b, Y2 z1 }7 x
& n6 K3 ^* \9 c% ]' t; K 'CommandButton1.Caption = "Use API code"; w4 Q, _2 @( z
+ J. B" S- Z4 C+ H ' start with some reasonable defaults/ u- p3 J m; ^7 `5 h
Commandbutton2_Click
: w. c- C1 V6 ]" O9 _" z: Y0 iEnd Sub |
|