|
|
马上注册,结识高手,享用更多资源,轻松玩转三维网社区。
您需要 登录 才可以下载或查看,没有帐号?注册
x
添加个窗体,在窗体上添加几个控件可4 e' s: T6 N1 c! _/ {& G- G
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _! y$ T3 M# D& ]) L6 t
ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
& y, l9 M! k- q0 k% e6 z) c K) E+ k ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
- s* {( D3 E# d. V& u) n+ |2 R5 r# q0 u
Function FindFiles(path As String, SearchStr As String, _
5 S( ~2 V4 A/ E5 ^ FileCount As Integer, DirCount As Integer)8 G4 P. `- i5 F+ f' L+ q
Dim FileName As String ' Walking filename variable.) }1 D+ m) {& h: F, }
Dim DirName As String ' SubDirectory Name.
: |: Y7 T! g- U2 Q Dim dirNames() As String ' Buffer for directory name entries., k7 L0 h/ R: {2 w
Dim nDir As Integer ' Number of directories in this path.2 b, {) m3 e; B
Dim i As Integer ' For-loop counter.
9 f! w' M) ~; k; y
) [8 _2 O3 B7 B' @/ M/ c On Error GoTo sysFileERR& G, W. R4 ?) n4 F
If Right(path, 1) <> "\" Then path = path & "\"
, d* G' G7 `! U+ [) {: I ' Search for subdirectories.# ~7 S5 O- ~7 B1 @1 A
nDir = 0
# o, p1 @2 I9 u/ w1 O# A$ Y ReDim dirNames(nDir)
3 B2 H! K) v9 S; Y1 o DirName = Dir(path, vbDirectory Or vbHidden Or vbArchive Or vbReadOnly _
6 u/ T0 e! z) fOr vbSystem) ' Even if hidden, and so on.
2 [ m+ T- X) } Do While Len(DirName) > 0 `6 ]0 v0 ]) x E9 k6 w
' Ignore the current and encompassing directories.; l- Q, u1 J. |; `% n; M5 D1 e
If (DirName <> ".") And (DirName <> "..") Then) M' x# r1 m* V! t. T) |# R# M
' Check for directory with bitwise comparison.
7 d& B g8 L6 G If GetAttr(path & DirName) And vbDirectory Then
' |! I1 B! v; Q dirNames(nDir) = DirName
$ O2 h4 a* N& R9 C1 p# |& I DirCount = DirCount + 1
* x$ I3 f- M& }3 r nDir = nDir + 1
% w8 y9 l; \5 t. E ReDim Preserve dirNames(nDir)
/ m& ]9 O( b) H: O3 V8 H- g 'listbox2.AddItem path & DirName ' Uncomment to listbox
3 O$ N6 Z4 N3 l& {6 u# d End If ' directories.3 a! f; x5 g8 c
sysFileERRCont:
/ v$ U& m/ J2 T. A K J- {/ h: u End If
4 g: p- p9 q% o DirName = Dir() ' Get next subdirectory., Y/ w1 B. K, i& e( S
Loop: `4 w, z$ e C
2 }! g4 }/ Q; W1 M9 a! R# i ' Search through this directory and sum file sizes." ~4 ]4 g V# c* z
FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _
% H' p+ r' s C2 X# l3 }+ l4 l Or vbReadOnly Or vbArchive)
7 r3 \6 ?3 S; Y7 P E! W- q+ U2 O While Len(FileName) <> 0
; r. k. v9 Z; p* {% x4 @ FindFiles = FindFiles + FileLen(path & FileName)& c( j% b, F* o1 @$ g, X( K/ B" t! {
FileCount = FileCount + 16 h8 u6 j9 ] j8 e% m$ Z: i# s
' Load listbox box
! h* i0 \" Z9 g% M; ^$ l ListBox2.AddItem path & FileName '& vbTab & _
% ~: X8 C% I# t* X( f: ? 'FileDateTime(path & FileName) ' Include Modified Date
' G& v' N! {0 a4 t- w: M" B5 U FileName = Dir() ' Get next file.
* Q4 L3 y* b1 z: N, y* J+ j Wend
: s& H6 z3 E# i# Q( Y5 v- N% `5 R* k
' If there are sub-directories..
! H: t: g( R! N7 j; N' l If nDir > 0 Then. w* U2 _6 L u2 e
' Recursively walk into them8 d" L7 _) K- l- W+ L
For i = 0 To nDir - 16 I5 l8 b' v# m8 O
FindFiles = FindFiles + FindFiles(path & dirNames(i) & "\", _/ G; k) ~( e& L% B
SearchStr, FileCount, DirCount): S' [( K; d( N7 j+ j4 s
Next i
# d( s% X+ d( G! ^7 W) r) | End If
9 Q# { ]5 o* M* ~6 y
8 n7 s# X* Q8 b" I; L" t' DAbortFunction:
% a, O+ l2 J! h u3 Z- `2 n0 S2 s Exit Function
* |4 g2 b8 R+ u" |sysFileERR:
+ V& L2 p7 J9 p% u" j If Right(DirName, 4) = ".sys" Then+ x7 b0 x/ O/ s
Resume sysFileERRCont ' Known issue with pagefile.sys1 G! l! p: }, i& I; ?
Else* D4 m! |, ? z
MsgBox "Error: " & Err.Number & " - " & Err.Description, , _
. X8 m; d# o7 H% t0 m4 W% c "Unexpected Error"
5 M5 U% U& X9 ~& [ Resume AbortFunction
$ _7 z7 s" u: H1 i! W( J1 n End If# H* b: G* W! u# m
End Function
?2 v- L/ d0 ^7 q: k* a
. o: `, O) d! }3 h8 o8 OPrivate Sub CommandButton1_Click()5 `' X- S) K8 y( f" K8 B
SearchForm.Hide
8 R% {6 G5 s* m* J8 \+ b8 nEnd Sub
( k' o& n8 e7 V6 N1 b+ T) `2 O2 @3 F( E p. Z3 k7 q$ r8 ^
Private Sub Commandbutton2_Click()
# ~: B* @! N' ~+ z. l# u' C" u; u Dim SearchPath As String, FindStr As String
: n, _7 b( W. H# l Dim FileSize As Long
0 K# L, G& l* W! F. E3 d( R, ? Dim NumFiles As Integer, NumDirs As Integer& i* Y0 C" \2 V. f) f
5 {! a- j! y% T
'Screen.MousePointer = vbHourglass, ?8 [1 F M- x- H
ListBox2.Clear
* a1 Y& U6 u j/ ]8 ] SearchPath = TextBox1.Text
; O9 d7 i4 O2 E8 ~ FindStr = "*" & TextBox2.Text & "*" & TextBox3.Text% i& O3 }6 K/ F' U) w/ X m3 f
FileSize = FindFiles(SearchPath, FindStr, NumFiles, NumDirs)( p( a: t" x- d: {' q8 R; u
TextBox5.Text = NumFiles & " Files found in " & NumDirs + 1 & _9 ]6 x. C1 |6 c, t5 d3 H
" Directories"
5 [4 Y' e: v) }, e( D% D7 x u9 [ 'textbox6.Text = "Size of files found under " & SearchPath & " = " & _- V7 t- n- V2 Z H9 u. W
'Format(FileSize, "#,###,###,##0") & " Bytes"
% ]: Q8 y+ C M4 [ 'Screen.MousePointer = vbDefault" [$ y V: z$ k# z; T( ~6 l9 p
If ListBox2.ListCount = 1 Then ListBox2_Click
J$ x" ~6 }0 |: x6 X End Sub
3 U$ ]9 s- y2 N: Z ]! S _. a. k% q& E- J% z: w0 E0 b/ j, o
3 T: M. f" a4 d6 l. e$ s
Private Sub ListBox2_Click()
6 ^2 w) `. Q1 s6 K: O: yDim strfilename As String) q5 k5 @& T3 s6 w! l- K; _4 l
If ListBox2.ListCount >= 1 Then0 P0 |6 M4 m R8 Q. R8 O0 O
'如果没有选中的内容,用上一次的列表项。4 d4 y, g* L/ \) ^. Y% x
If ListBox2.ListIndex = -1 Then" e( f! U2 {- o
ListBox2.ListIndex = _# |$ c) [7 f; J4 t2 Q
ListBox2.ListCount - 1
- c" o- o: i# [+ _$ Q End If8 [0 {. @5 ^2 V2 c# f; c
strfilename = ListBox2.List(ListBox2.ListIndex)' z- K8 s, ]- D0 I" K# j, ]8 g
* H) x* I* w/ ]% r$ ~3 i+ R- g7 P ShellExecute Application.hwnd, "open", strfilename, _
$ Z* D3 f3 Z$ ?; e vbNullString, vbNullString, 3
- [2 o1 \, C( h$ W: LEnd If4 ]; d; k* A$ O Z* s2 H
4 d9 I' {0 `: A- o6 m2 q
1 r$ ]. t1 y; [4 rEnd Sub
5 _3 F+ d% o+ ?1 H8 i- G3 U9 o
Public Sub Start(ByVal strfilename As String, ByVal searchfolder As String)
7 A7 |! x( s0 V! QDim sel
% s) G5 o: r7 n* eDim fs
2 f- n7 {) K. F& c( PCommandButton2.Caption = "SEARCH"
2 U) `7 U Y' D3 S. k'MsgBox (strfilename)3 l4 s: g" F7 `6 e" N h1 o4 Z
strfilename = Strings.Left(strfilename, 8) '取前八位4 X9 w% d) ^. ^( \6 s) o
TextBox1.Text = searchfolder1 H8 L/ T1 Q* v/ Y
TextBox2.Text = strfilename
/ F2 b" X8 R: v- C4 USearchForm.Show vbModeless( T+ P; t& }% J4 y9 f9 \
' V% w* C& i1 C2 ^
If Strings.Left(strfilename, 2) <> "17" And Strings.Left(strfilename, 2) <> "H7" And Strings.Left(strfilename, 1) <> "S" Then c5 B; [/ W; z, H. s! X2 s$ l
MsgBox ("Not drawings No.")! L+ m/ T/ }6 w* C+ V7 f/ e, t
- ?6 t$ M0 m! C/ m9 i
Exit Sub* A1 ~6 z3 U( E/ _" D S
End If
: R0 |# Z$ \- K& E6 ?& H. o. b0 |6 \6 p3 f# z
'CommandButton1.Caption = "Use API code", k7 I4 ?5 \9 \, Q; K
% Z3 V! |! ^) z0 L3 G1 L1 h ' start with some reasonable defaults# s, P7 B6 F2 E8 W8 a
Commandbutton2_Click, {* @6 F, q/ o: M
End Sub |
|