-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModule2.bas
103 lines (74 loc) · 2.72 KB
/
Module2.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
Attribute VB_Name = "ModJunk"
Option Explicit
Public JunkVal As String
Public ExtArray() As String
Public ExtArrayCounter As Long
Public JunkFileArray() As String
Public JunkFileArrayCounter As Long
Public spString As String
Public Function JunkArray(argJunkVal As String) As String
Dim JunkExt As String
Dim Position As Long
Dim counter As Long
Dim PositionOld As Long
Dim LastCommaPOS As Long
Dim LastComma As String
ExtArrayCounter = 0
PositionOld = 0
Position = 1
counter = 0
ReDim ExtArray(ExtArrayCounter)
Do While InStr(Position, argJunkVal, ",")
Position = InStr(Position, argJunkVal, ",") + 1
JunkExt = Left(argJunkVal, Position - 2)
If counter = 0 Then
Else
JunkExt = Right(JunkExt, Position - PositionOld)
End If
ExtArray(ExtArrayCounter) = JunkExt
ExtArrayCounter = ExtArrayCounter + 1
ReDim Preserve ExtArray(ExtArrayCounter)
PositionOld = Position + 1
counter = counter + 1
Loop
End Function
Public Sub subFindJunk(Optional fDirArray, Optional fDirCounter As Long)
Dim f As Long 'Place holder for each element in the array
Dim e As Long
Dim CurExt As String
Dim CurJunkFile As String
Dim fName As String
Dim fPath As String
'Loop thru all directories and for each file call the "AddToFileArray"
'This is done one directory at a time to keep all files separate when in dir dirs
JunkFileArrayCounter = 0
ReDim Preserve JunkFileArray(JunkFileArrayCounter)
On Error GoTo ErrorHandler
For f = 0 To fDirCounter
frmMain.ProgressBar1.Value = f
fPath = fDirArray(f) & "\"
If Right(fPath, 2) = "\\" Then
fPath = Left(fPath, InStr(1, fPath, "\", vbTextCompare))
End If
If fPath <> "" Then
For e = 0 To ExtArrayCounter
CurExt = ExtArray(e)
If CurExt <> "" Then
CurJunkFile = Dir(fPath & "*." & CurExt & "*", vbReadOnly)
Do While CurJunkFile <> ""
If CurExt <> "." And CurExt <> ".." Then
JunkFileArray(JunkFileArrayCounter) = fPath & CurJunkFile
JunkFileArrayCounter = JunkFileArrayCounter + 1
ReDim Preserve JunkFileArray(JunkFileArrayCounter)
End If
CurJunkFile = Dir
Loop
End If
Next e
End If
Next f
Exit Sub
ErrorHandler:
Call ErrorHandler(Err.Number)
Exit Sub
End Sub