|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
添加个窗体,在窗体上添加几个控件可$ }% H/ h, {7 E$ x- `% S2 k
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
( ?, [! A' F: i! k5 v ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
7 W: s) a" h0 U ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long7 X5 q0 B9 o' }/ J
9 Y& q: { T- `
Function FindFiles(path As String, SearchStr As String, _
$ E+ e; l. R# p! P FileCount As Integer, DirCount As Integer)
% M% j5 Z# t' r; G4 X @ Dim FileName As String ' Walking filename variable.' L3 Y: e9 ~9 o. D( ~
Dim DirName As String ' SubDirectory Name.! S3 Y9 C2 Y% Z" c t) }+ C
Dim dirNames() As String ' Buffer for directory name entries.
7 h0 I9 X" M. q! q; J: T Dim nDir As Integer ' Number of directories in this path.
/ Z% O; m3 B. c# T# q Dim i As Integer ' For-loop counter.# z3 ^( _3 |7 `6 g0 y. O( p
) Y0 ? x5 n3 c0 L On Error GoTo sysFileERR
7 P9 b% M9 M0 L# P If Right(path, 1) <> "\" Then path = path & "\"
; T' y. U. _, h5 K ' Search for subdirectories.
5 v5 ` v! l& U% A nDir = 0
- p6 u" ~) w) z4 R( O1 H# s ReDim dirNames(nDir) s1 U' l, j4 j! i8 N
DirName = Dir(path, vbDirectory Or vbHidden Or vbArchive Or vbReadOnly _7 A5 \, G+ j" v/ k" d8 X/ ~% `
Or vbSystem) ' Even if hidden, and so on.
r# Z9 b0 O: M. U( E% A Do While Len(DirName) > 0
- t; }6 l% h: X+ Y; [ ' Ignore the current and encompassing directories.
3 a. Y& P: _. n& p! \ If (DirName <> ".") And (DirName <> "..") Then$ X. A! h& Q, v8 I9 T! m x% o
' Check for directory with bitwise comparison.' p3 D9 l+ J% `" Y8 w
If GetAttr(path & DirName) And vbDirectory Then0 o I6 s; R3 m* ~9 ?0 m7 q
dirNames(nDir) = DirName. B) E( G, D; A) z# X5 j9 r3 _! Z
DirCount = DirCount + 1- }) V! |3 }8 }/ B7 }3 y
nDir = nDir + 1
$ |) J, ?$ s. z! ]1 t- j ReDim Preserve dirNames(nDir), `" N& a: g# w* N- n* b
'listbox2.AddItem path & DirName ' Uncomment to listbox3 I% F5 ^8 X- o0 S
End If ' directories.: f4 r$ S3 D3 w; n/ P7 i
sysFileERRCont:
/ F/ h8 I+ T8 z* ]/ g8 S: h End If( O" V4 k/ `/ d
DirName = Dir() ' Get next subdirectory.
4 X7 N d" h$ P) u2 ^3 v& I Loop# S- L4 N. k4 B$ l' d
: o; V4 z8 \8 x5 i" ~
' Search through this directory and sum file sizes.
; B; y- q8 p8 A0 `& y k FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _* @0 m3 ~. o. o; U6 r5 e
Or vbReadOnly Or vbArchive)
3 F1 V0 z- s+ c% h6 F; H. m While Len(FileName) <> 0
. G9 L; [5 c6 }6 O; D: t' B. t FindFiles = FindFiles + FileLen(path & FileName)
5 \5 K! W$ N1 N FileCount = FileCount + 1) D7 Z& X, {" [
' Load listbox box. X" S1 `6 H9 [6 b* Z( F
ListBox2.AddItem path & FileName '& vbTab & _7 m3 e( K1 |) B. c7 l3 x
'FileDateTime(path & FileName) ' Include Modified Date
& L! e7 H; o. G- r5 g; N FileName = Dir() ' Get next file.
$ W* K0 o' w- ~# b3 i6 Q Wend: ^& C, x9 R3 s4 z+ S
* a1 v3 n1 t' p- W$ D ' If there are sub-directories..
4 V* b* T2 a H& m! s1 H If nDir > 0 Then
8 f2 B& f8 W# n; H# A/ p5 K ' Recursively walk into them
1 m: _. w8 v, }( q: q/ D4 H For i = 0 To nDir - 1
/ n" X* R+ R% v FindFiles = FindFiles + FindFiles(path & dirNames(i) & "\", _
" s( g7 {0 h: a% L, x SearchStr, FileCount, DirCount); i1 n5 Y" A# s8 \
Next i
0 j* g5 L, S9 `& D6 b `' X: d8 ] End If
% ?/ v) N! ]9 n+ k, v5 R0 g" s4 b; f; m5 v+ v3 \. w8 T* `) \
AbortFunction:7 n$ t! x, y* q. |7 h' w. c) X
Exit Function
1 I, S: P& i: ]sysFileERR:
; D+ r+ i# l: ~# n3 ~' [ If Right(DirName, 4) = ".sys" Then8 Q8 C1 O0 `2 d2 |7 J
Resume sysFileERRCont ' Known issue with pagefile.sys/ k0 [7 D0 M7 w. Y
Else+ P( W Y3 _ f/ s4 [
MsgBox "Error: " & Err.Number & " - " & Err.Description, , _
, A( F$ K2 q$ z/ C$ ~ "Unexpected Error"
/ l2 U) |" O( [! b/ @ Resume AbortFunction/ X, e( q5 Y1 `0 d& g# d
End If
7 e8 A/ [ ^6 t* }* a: T0 d9 | End Function
. x8 J! v& |5 B% s& M* R) a" ?8 y0 ^/ V$ _+ @+ v
Private Sub CommandButton1_Click(): N: S, Z8 w9 U9 m
SearchForm.Hide' Q9 k+ u7 W. d; z: B% q
End Sub( y: }/ O A ]7 K
: S/ b) | D( M# ~( l
Private Sub Commandbutton2_Click()
" a6 ~7 x" R ~ |2 u/ d$ n Dim SearchPath As String, FindStr As String/ t, v% W: I9 \# Q4 R) V* k
Dim FileSize As Long1 V. A8 }. P' c
Dim NumFiles As Integer, NumDirs As Integer _. \) G) I2 g
" a6 u4 K! A5 x/ W0 y8 B# p% Q$ c 'Screen.MousePointer = vbHourglass4 k# V. t& m' M1 d6 A3 C
ListBox2.Clear
6 I; u( E1 k/ `8 A; [: L SearchPath = TextBox1.Text+ j: e$ i" n4 V: l' N3 D) ]
FindStr = "*" & TextBox2.Text & "*" & TextBox3.Text
4 l' x% h1 d5 G& l) E. h0 P1 R0 ^ FileSize = FindFiles(SearchPath, FindStr, NumFiles, NumDirs)
1 N5 E5 z' _2 K2 f$ n& W TextBox5.Text = NumFiles & " Files found in " & NumDirs + 1 & _2 T$ [4 [# L! q$ A6 S
" Directories") N4 Q u, U, [" h- O
'textbox6.Text = "Size of files found under " & SearchPath & " = " & _% d* }$ K3 c2 f
'Format(FileSize, "#,###,###,##0") & " Bytes"7 L2 m2 L( ~2 A5 C
'Screen.MousePointer = vbDefault5 y+ }0 }0 t% T9 A4 q$ N
If ListBox2.ListCount = 1 Then ListBox2_Click, \. i9 n% d! H+ F( f
End Sub- j$ d* ?7 F4 u) p( j; h
7 B; ~+ s- }2 X! e
0 s$ J- M# h6 |- IPrivate Sub ListBox2_Click()2 y8 H) c6 f$ O# j% }3 o5 [
Dim strfilename As String# b x) P5 E: D5 d( E+ n
If ListBox2.ListCount >= 1 Then
' @0 O/ ]% j: W9 k '如果没有选中的内容,用上一次的列表项。, T+ }& J5 n: i, U
If ListBox2.ListIndex = -1 Then
2 m( A, {# G5 ~6 _ ListBox2.ListIndex = _: T" N1 `9 U- J3 e: c# `0 F; X. z" C
ListBox2.ListCount - 1
: F' `% {2 e6 X End If
3 N5 t# [0 u7 X% ` Z4 _. W; { strfilename = ListBox2.List(ListBox2.ListIndex)9 L; u* \0 _1 a0 h
2 ` j6 B6 A/ Q8 g/ N2 e ShellExecute Application.hwnd, "open", strfilename, _. t6 Q, R! `( ~
vbNullString, vbNullString, 3
+ j. ?8 R- Y# \; C- a3 l4 A, C; JEnd If
5 Y& Q7 C- i0 T* I% d/ m% U1 G* H2 {- o2 \
5 e% s$ x1 h9 Q% l0 Q, s/ y
End Sub4 v: X0 A( j+ Z6 C) O+ m4 E* {
* M: i1 Z! c8 y# A) Q- G
Public Sub Start(ByVal strfilename As String, ByVal searchfolder As String)
) m, J' s4 x/ z& J e3 QDim sel
& f# q4 N4 T3 v) x5 v2 L9 {Dim fs
# ~& b7 p5 {: q2 j( e7 e$ ~6 ICommandButton2.Caption = "SEARCH"
. o5 `, i4 W3 a'MsgBox (strfilename)- B1 D+ t2 n R# w1 C* O/ ]. ^& {
strfilename = Strings.Left(strfilename, 8) '取前八位
$ I; R6 [3 p2 V- a& y. f6 I% YTextBox1.Text = searchfolder
& x$ b) K5 a2 J6 z5 cTextBox2.Text = strfilename
a7 F6 K0 X* q, ?' n+ e$ X! s$ SSearchForm.Show vbModeless4 p8 T- N" |7 F/ V, G! ~7 A
+ \6 a, D$ R: v
If Strings.Left(strfilename, 2) <> "17" And Strings.Left(strfilename, 2) <> "H7" And Strings.Left(strfilename, 1) <> "S" Then
6 v. N5 w0 E9 {' j3 c. }% y6 n MsgBox ("Not drawings No."): X* k* W+ S8 U# Q" R
5 P# \' r( Z- p+ ]% y Exit Sub" g9 _( |6 q4 }( @
End If
4 N2 i# }8 j1 t6 ]/ l o. `' y! u0 ?* A+ B0 k2 N& u
'CommandButton1.Caption = "Use API code"
* r5 E0 B& o2 f
! z7 o, c- a& i k) E. @8 z ' start with some reasonable defaults5 G6 P. ~7 W& E0 {
Commandbutton2_Click
4 @; @0 I9 `+ N" uEnd Sub |
|