|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
添加个窗体,在窗体上添加几个控件可+ Q, K h3 f* i3 Y0 t- T
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _: {* T& T" b1 m( S6 q K6 T1 k* b6 N
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _& I$ g6 V s+ h, b
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long4 D' }: ^1 Z: A7 [- V5 [, ~! b; d Z
4 S3 J, H; y" D6 Z6 J* |) iFunction FindFiles(path As String, SearchStr As String, _+ V8 U K/ [" r7 V; F
FileCount As Integer, DirCount As Integer)
' p$ O; D8 v# _+ D Dim FileName As String ' Walking filename variable.3 H% G' `. b/ u# W( v* Y
Dim DirName As String ' SubDirectory Name.
! ]- d# ]# o' q8 s Dim dirNames() As String ' Buffer for directory name entries.7 x- {2 l1 l$ J% { c6 j
Dim nDir As Integer ' Number of directories in this path.2 [; O1 `4 p3 Z- x2 U
Dim i As Integer ' For-loop counter.
& ]( o. o! y5 u! `! o$ R5 i h7 t) k/ F2 W* ]6 F
On Error GoTo sysFileERR
. @% m7 e* s: J0 @+ @) C If Right(path, 1) <> "\" Then path = path & "\"
: N% _9 t$ F8 y8 }8 i. S# q ' Search for subdirectories.* U6 [2 L% t E D* _
nDir = 0 J+ Z$ _) r5 m8 _4 ?
ReDim dirNames(nDir)
e6 M) L. _5 Y7 X! N# A DirName = Dir(path, vbDirectory Or vbHidden Or vbArchive Or vbReadOnly _
: H3 q5 O* X) |: u3 r" ?0 {Or vbSystem) ' Even if hidden, and so on.% T3 X$ l! q, V2 i8 v0 Q
Do While Len(DirName) > 0% F q) l7 B9 Y, a0 t
' Ignore the current and encompassing directories.5 G' A9 p3 `7 D1 C
If (DirName <> ".") And (DirName <> "..") Then
7 C' w% X& v, W. M) y1 ^ ' Check for directory with bitwise comparison.
. E2 T3 v% T* X& S% o If GetAttr(path & DirName) And vbDirectory Then6 J* O; T+ O- c3 z0 {5 ]
dirNames(nDir) = DirName9 [* o9 |9 y! g. w
DirCount = DirCount + 1
; y: Z8 o1 C3 P nDir = nDir + 1/ z; I4 I, X! `! v
ReDim Preserve dirNames(nDir)
( I. Q% `% e! J' Y 'listbox2.AddItem path & DirName ' Uncomment to listbox
0 }& f( t- @7 x+ g2 O End If ' directories.
% S) \- [" w! ]& e. ^% l( }. JsysFileERRCont:4 x* V; b7 o. ^8 f; D* b& j$ o
End If
8 `. K# `* A" }6 n. O0 F; w* i6 N$ [ DirName = Dir() ' Get next subdirectory.
' [9 Z0 y6 t- [/ U; X$ x Loop
6 N B7 r+ b0 w
$ p8 p' ^: C- D: e ' Search through this directory and sum file sizes.) e: j1 I" `) z+ o$ d( P
FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _) t4 P$ L+ e* n
Or vbReadOnly Or vbArchive)3 V2 ~3 _7 ]. u: D- [0 Y
While Len(FileName) <> 0
5 ~1 j G! Q( H' P FindFiles = FindFiles + FileLen(path & FileName)
6 r3 U- ~+ n, c6 o* {' Q& { FileCount = FileCount + 1" p- N) h% z b& i- Y d6 B
' Load listbox box8 w) x6 _3 F+ |4 o: B
ListBox2.AddItem path & FileName '& vbTab & _
; A. i! `" a7 s 'FileDateTime(path & FileName) ' Include Modified Date9 b' Y& w! k# N {. z6 E. J
FileName = Dir() ' Get next file.
! n8 P( K5 _# k" K" s7 \* T, n, l* _ Wend# h! p: c7 q+ n" H- H2 m, o
, o9 W% m7 D/ c6 x9 W I! n' C
' If there are sub-directories..
* J6 [* U* p" e5 p2 g/ {" E* I2 f If nDir > 0 Then
6 G$ {% u: _- y# R4 |. _- R ' Recursively walk into them. S) k# P4 ^3 d8 X, S% E6 |
For i = 0 To nDir - 1 o3 E6 O, g* ^; s2 c9 k
FindFiles = FindFiles + FindFiles(path & dirNames(i) & "\", _
: [) w) ?0 u; @' Q+ [ SearchStr, FileCount, DirCount)0 @3 ^ G, \& I( ~& W( L8 g' H
Next i7 E; T; H8 i1 T- X
End If' Y& |9 Y x" ~- E& |) l
* Q# c: f8 Y6 m& l0 ?( H; [
AbortFunction:/ ~& i8 p# o- o7 |6 `
Exit Function
) w' }! a; A2 S3 VsysFileERR:
/ W q/ G" ^( O: t" m; b5 ] If Right(DirName, 4) = ".sys" Then
& z e7 W8 \# V* K, G( Z Resume sysFileERRCont ' Known issue with pagefile.sys7 G6 ~) g2 N, e( b6 y4 }' O7 W& C
Else1 K @" h a8 R+ w5 H' }) Z% F4 D
MsgBox "Error: " & Err.Number & " - " & Err.Description, , _ \: Y* k; a" B* n/ v% B
"Unexpected Error"
; X- E3 {0 V: S! }4 j Resume AbortFunction' e4 c( z1 n5 P1 r" L# b; M
End If" k2 L: l1 F. r5 s& K: Y
End Function
. S& H5 E$ E1 Y: L3 ?8 H
+ U2 \ Q [$ f8 `Private Sub CommandButton1_Click()
. v6 `" [" [! rSearchForm.Hide
/ m q( t0 \: h/ s: G0 G7 YEnd Sub
, [3 i) M' c6 i8 E7 v3 [7 l
4 Z- T6 R4 M3 M Private Sub Commandbutton2_Click()
- C& E5 h7 p) Z! l3 G$ { Q Dim SearchPath As String, FindStr As String
6 C2 R: e' W K# O3 J: ~ Dim FileSize As Long* ]4 Q8 @& W9 X: a. O
Dim NumFiles As Integer, NumDirs As Integer$ _" N4 P: }' Y4 o5 }, g% A i
- R& P* @8 l- T6 O* i 'Screen.MousePointer = vbHourglass
L) ?& v! |, L% ~3 j+ U$ J% J ListBox2.Clear
2 `0 v# Z9 ~& D. t8 N2 f) h: I SearchPath = TextBox1.Text9 e2 Z) Z4 r3 o# C. u& f
FindStr = "*" & TextBox2.Text & "*" & TextBox3.Text
% R6 M1 x$ t0 l5 r' B& ?* Q4 d- p. N FileSize = FindFiles(SearchPath, FindStr, NumFiles, NumDirs)
. _( u2 w: P/ P' b6 O: W TextBox5.Text = NumFiles & " Files found in " & NumDirs + 1 & _
; K! i1 ~: e9 U) N$ G3 a " Directories"
/ ?$ r! U1 S) w' { 'textbox6.Text = "Size of files found under " & SearchPath & " = " & _
; G7 d6 x9 x4 u; X6 u; c& A 'Format(FileSize, "#,###,###,##0") & " Bytes"
4 v) N6 A6 X& E0 ~5 \# o+ V! C; ~ 'Screen.MousePointer = vbDefault
- A: A% c( a) x, H' [, | If ListBox2.ListCount = 1 Then ListBox2_Click1 Q0 K9 m7 d- e/ t* j' y2 @% t7 D
End Sub3 R2 r! H! u* G
& ?: V3 F) J) y1 r
7 k: T( n9 A' k& ^% Q$ GPrivate Sub ListBox2_Click()$ Y6 o5 t) R$ {( `4 z# h
Dim strfilename As String! c7 Y; f4 ]1 n; x1 P0 q
If ListBox2.ListCount >= 1 Then
2 o6 e' [, j/ { '如果没有选中的内容,用上一次的列表项。
' J: z' w# J6 \+ g" u0 I If ListBox2.ListIndex = -1 Then
) f0 A! v4 W( V, N2 t) { ListBox2.ListIndex = _
4 H4 G& d# s3 k/ M' G) ]5 L G3 g J9 z ListBox2.ListCount - 1
, J6 @; `. T4 p. K0 Q End If( E, E3 O- P- }, l# g
strfilename = ListBox2.List(ListBox2.ListIndex)3 W& e2 |$ r" o: s, E/ a9 o" `' n
; e+ q$ e4 U' M8 c# b0 w" t
ShellExecute Application.hwnd, "open", strfilename, _
9 t4 g2 k8 P. x4 t vbNullString, vbNullString, 3
- V. z- I( m" C4 Q' gEnd If* v. z' n4 }2 ?# N
2 O% `2 K- N6 @" c1 D6 l! t: C( [" ? s( J( h) _
End Sub* W# C- e4 K0 o9 {: A1 V. x( a
1 P+ P7 N+ p8 B9 g# OPublic Sub Start(ByVal strfilename As String, ByVal searchfolder As String)
; C1 g) U1 \8 V, ?4 \Dim sel% a2 |+ Q2 f' }" K1 Q7 Q
Dim fs" R1 K* t) _" f
CommandButton2.Caption = "SEARCH" W5 w4 E/ C0 C$ A+ z0 q
'MsgBox (strfilename)
J. \/ T ]; o# x" P2 wstrfilename = Strings.Left(strfilename, 8) '取前八位
/ J: w- T2 d. _TextBox1.Text = searchfolder
. u6 l6 g* V5 X; z( T& R/ \5 f. ATextBox2.Text = strfilename
) U/ J8 M4 a9 O) ^3 q$ kSearchForm.Show vbModeless
0 g$ h+ |" s( Q& W7 e k1 s6 p- D v7 N
If Strings.Left(strfilename, 2) <> "17" And Strings.Left(strfilename, 2) <> "H7" And Strings.Left(strfilename, 1) <> "S" Then
, D" i( I# ]; N: U1 ?! W MsgBox ("Not drawings No."), L, K: l4 D, G8 |
. D2 d3 S6 e N8 f) P Exit Sub+ {% j- |" w, u- c: R; ?
End If
9 {! _, v8 c. K# f8 R" p' b4 z- z9 z0 i, ~; a3 s/ }" p( j$ D
'CommandButton1.Caption = "Use API code"! ^' f1 j- j$ }5 y
# y, D9 U0 C7 ]
' start with some reasonable defaults
6 v* A! M+ o$ b5 D; Z Commandbutton2_Click9 R, z- L# [; p) C6 y0 X. ~: ^
End Sub |
|