|
|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
添加个窗体,在窗体上添加几个控件可
8 d8 `7 T8 u* W2 _) v W0 k/ lPrivate Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
2 Q/ F% ^6 i/ i; a" O+ S9 ] ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _- `& ?, e2 k6 p
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
( Q+ v2 F ~) b! a+ U! r
& |# S. e5 s7 D7 SFunction FindFiles(path As String, SearchStr As String, _9 t+ u' y7 Y" z, s, C
FileCount As Integer, DirCount As Integer)
. e& v5 [, i0 f; z: _7 E Dim FileName As String ' Walking filename variable.
9 _( a# z% b) t+ C, j Dim DirName As String ' SubDirectory Name.9 W" B; m' u& Q3 s! ^
Dim dirNames() As String ' Buffer for directory name entries.
( H) z; o( V/ N! W Dim nDir As Integer ' Number of directories in this path.
- ^! T0 n* ?0 k# M Dim i As Integer ' For-loop counter.
& _9 ^% q0 i- Y) z* ?+ f p* {. i8 F; s1 f4 M" d: ?
On Error GoTo sysFileERR
7 i" w ^6 ~ |4 }5 _. c9 z If Right(path, 1) <> "\" Then path = path & "\"3 u4 z1 F, Z7 O A% L# R
' Search for subdirectories.1 D- I0 j: I& R! [+ E* r7 s: ]
nDir = 03 R, C% T& x/ y$ S- ~
ReDim dirNames(nDir)
& X* K2 J( A9 k7 x4 \. b% E DirName = Dir(path, vbDirectory Or vbHidden Or vbArchive Or vbReadOnly _ ~, [$ K5 u( B/ w
Or vbSystem) ' Even if hidden, and so on./ c4 b H( S9 S2 v/ ]+ _) a: \
Do While Len(DirName) > 0 j8 T: l% K$ |$ l
' Ignore the current and encompassing directories." D, K7 g1 A8 r3 e2 [- t
If (DirName <> ".") And (DirName <> "..") Then4 ?" p+ q! Q0 @ s8 T7 h
' Check for directory with bitwise comparison.- a. s4 F4 _ Y w; B) e4 f) P
If GetAttr(path & DirName) And vbDirectory Then
8 Q S6 |# r# `# L/ n dirNames(nDir) = DirName) K- Z! Y O! ]
DirCount = DirCount + 1
6 O, K) h) b! Q' E6 ~9 } nDir = nDir + 13 @( C# a4 G6 b2 u5 u) V8 v
ReDim Preserve dirNames(nDir)
1 o& Y9 Y B' i; g5 f2 ~ 'listbox2.AddItem path & DirName ' Uncomment to listbox
3 w0 L2 N3 t. q" l w End If ' directories.
1 M$ T8 D3 R: v7 h0 |% |! jsysFileERRCont:
3 Z( S1 Z" @* E End If$ l8 P" {7 Q l6 r
DirName = Dir() ' Get next subdirectory.. U# c/ V. w; ^- _( ^
Loop
) |+ X. F. r, q- i' X2 D5 Y" k$ k. k& ?9 j% d9 L. Z' W f
' Search through this directory and sum file sizes.
0 s) E' K" z4 U Z% p& h FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _
4 f, R* ^+ ^5 ~! W/ ^0 \2 t; W Or vbReadOnly Or vbArchive)% j8 k7 P g$ b( c z
While Len(FileName) <> 0
2 U! g( E' J4 N/ L4 y, j FindFiles = FindFiles + FileLen(path & FileName)) g- k1 \! ~# }1 p. D; @' p; J
FileCount = FileCount + 1
+ O/ b$ L: G* t2 u1 O ' Load listbox box
. k1 N. Y5 d9 c7 h* t4 Z; B) Z ListBox2.AddItem path & FileName '& vbTab & _
& h* ]$ v* A: b! ?- V' C 'FileDateTime(path & FileName) ' Include Modified Date6 G) x# c8 L2 L# O$ b
FileName = Dir() ' Get next file.
$ f4 W7 h7 u$ L5 E+ E9 G8 o& C Wend
& ?/ h, F" M+ V; o0 \- T# D8 y! K* U8 ^! [1 [0 d
' If there are sub-directories.." N) j- A* G2 ?
If nDir > 0 Then
/ m0 n$ ?+ b b, I; R ' Recursively walk into them
i6 q' z3 }. d; _ For i = 0 To nDir - 1
9 _6 m, C8 O8 k& H1 ?2 y* R FindFiles = FindFiles + FindFiles(path & dirNames(i) & "\", _
) M+ J) I4 D& e" ^ SearchStr, FileCount, DirCount)
" w& n# U% P) i$ [1 N. p% Q1 K! E Next i( ^; T+ C) W- q& v
End If( w, d; Y; O; B+ I) ]( S
0 B% q. |: _! W$ e- D2 j, v7 VAbortFunction:
' p7 f9 w. S$ v0 _: p5 n* N Exit Function& c; W& a3 \3 k9 L! s+ `
sysFileERR:
* i# N; b. }1 g* T/ x7 d. I If Right(DirName, 4) = ".sys" Then8 q! L, ?; D. R% g
Resume sysFileERRCont ' Known issue with pagefile.sys
|/ ^' a2 f F, X4 }2 i Else3 x+ S; ?1 s' |; J& N
MsgBox "Error: " & Err.Number & " - " & Err.Description, , _; v- A* x0 C7 p7 F g: d6 U
"Unexpected Error"
4 V, s @& y0 {0 {0 }3 A. R* \ Resume AbortFunction
* v/ I) N1 y% l/ Z End If
' V( u; U a- |* @. y: n0 F2 u End Function
0 x: l. {6 G3 A$ T' i. N. J4 q( j+ d. }% |* ^5 C- V
Private Sub CommandButton1_Click()- g B( I; f6 L1 G2 s3 g4 N
SearchForm.Hide# x" \- D. d. p
End Sub
8 F+ |1 q: o. d4 J8 o% |
* {0 ? n$ B. q Private Sub Commandbutton2_Click()
5 Z- E w' ~( v! F) g; w Dim SearchPath As String, FindStr As String
1 N) c* W# @; a/ P8 G Dim FileSize As Long
# p/ u$ t! w0 C$ t" J; W9 o3 X Dim NumFiles As Integer, NumDirs As Integer
+ k( v; @- C2 Q$ M
' ~8 Q/ {. M; D1 q6 j' n 'Screen.MousePointer = vbHourglass
: r9 @* r: Y; W7 ^/ i ListBox2.Clear% {. u* T8 A4 t/ g" Q) u2 M8 o4 I
SearchPath = TextBox1.Text$ x0 K* t T. _9 h
FindStr = "*" & TextBox2.Text & "*" & TextBox3.Text$ r2 ]9 a6 w9 C- T: j) U4 P7 f
FileSize = FindFiles(SearchPath, FindStr, NumFiles, NumDirs)7 ~$ x' c+ S# }3 r
TextBox5.Text = NumFiles & " Files found in " & NumDirs + 1 & _
; f& P+ d) d" S " Directories"0 j' `- l! B( P" ~
'textbox6.Text = "Size of files found under " & SearchPath & " = " & _
5 u- ~& F7 V# y" H4 M! Y 'Format(FileSize, "#,###,###,##0") & " Bytes"
- ?" ^2 T* T; {% w: m s9 F 'Screen.MousePointer = vbDefault
$ ~& g6 P5 J9 P* \* s+ o* \; K If ListBox2.ListCount = 1 Then ListBox2_Click. D$ e) l; P) L* L5 P- O1 U
End Sub1 C; W; ]! ~9 M) J* B2 A4 H
# L: U4 L" h8 ?4 w7 [" g
7 P' J/ \' Y8 R9 jPrivate Sub ListBox2_Click()# K2 W+ q: o7 Y3 m5 ^& |4 i
Dim strfilename As String
% N$ r( @0 q7 P$ w; T! x; r; pIf ListBox2.ListCount >= 1 Then2 G8 H/ E2 U7 T- q+ ^ V* A
'如果没有选中的内容,用上一次的列表项。3 D. j) U2 |. h! m& b
If ListBox2.ListIndex = -1 Then
1 d7 ]( S5 ?8 x! L9 { ListBox2.ListIndex = _, g& K+ L5 I; ], F: R j
ListBox2.ListCount - 1/ y# b4 p! p1 @! b
End If& n% j+ w1 ~+ ^' T9 f$ T
strfilename = ListBox2.List(ListBox2.ListIndex). I' \! D, }( g- k$ g5 A
8 w3 a% V, U. ^3 l, w9 P5 M ShellExecute Application.hwnd, "open", strfilename, _
) C8 V. A4 B3 U6 A. ` j% ^8 b/ A vbNullString, vbNullString, 3# O! ^7 F) k0 Q% U/ _% w
End If5 X, C# j" v/ O; Y
2 |1 J( Q: i0 ]+ q$ T# x% f! L
7 B1 p {( T D3 T
End Sub: `2 J( D" G0 ?; r
; {( h+ \, d0 ] N7 uPublic Sub Start(ByVal strfilename As String, ByVal searchfolder As String): _+ t! X* {% {% H; X. }1 E; W2 o
Dim sel: S6 p! h- H4 s2 o T
Dim fs
5 ?- T6 i. ~( r9 B, YCommandButton2.Caption = "SEARCH"3 J: m$ k/ G) x
'MsgBox (strfilename)3 K7 U- S- j4 z z$ w0 x/ |
strfilename = Strings.Left(strfilename, 8) '取前八位$ _0 [2 B- x6 \/ `: O
TextBox1.Text = searchfolder. k/ p5 l' }# T7 ~
TextBox2.Text = strfilename
9 x7 B5 y0 M* K3 zSearchForm.Show vbModeless
+ U( G9 _) E0 A! G* ?# C, a
( V0 B& m- y) a2 QIf Strings.Left(strfilename, 2) <> "17" And Strings.Left(strfilename, 2) <> "H7" And Strings.Left(strfilename, 1) <> "S" Then5 {; A2 h% a: F4 ]" q e
MsgBox ("Not drawings No.")! [1 R2 m- x. M+ q) K4 C: p
, e$ i+ Q( x. a8 @) J J* e0 | Exit Sub1 Z! b: a& u+ a6 i3 |
End If0 P4 H. o! [' [7 Z5 Q
3 }, z9 V. a+ c! M9 c. S% |% h* v
'CommandButton1.Caption = "Use API code"8 R- r* n9 K0 ]# \4 _% S# C
4 D6 Q0 ?- M5 o2 L ' start with some reasonable defaults1 _% v0 O4 ^+ ?+ j; m, I3 O4 @2 @
Commandbutton2_Click
0 {0 z$ n) f0 G9 I- sEnd Sub |
|