I am trying to incorporate an exclude folder path list into my main workbook so that AFTER I click the button to search the excluded folder paths will not be included into the final list. How can I do that? I am attaching the exclude folder code and also the main code.
This is the excluding folder code (Note: this only works for 1 path but I want to add multiple exclude paths in deeper levels within the parent folder)
Option Explicit
Sub test()
Dim i As Long
Dim MiMatriz As Variant
Dim STRexclude As String
STRexclude = "\subfolder 1"
MiMatriz = Range("A1").CurrentRegion.Value
For i = 1 To UBound(MiMatriz) Step 1
If InStr(1, MiMatriz(i, 1), STRexclude, vbTextCompare) = 0 Then
'do something
debug.print MiMatriz(i, 1)
Else
End If
Next i
Erase MiMatriz
End Sub
This is my main code that I want the exclusion folder and subfolder paths added to:
Option Explicit
Sub SomeSub()
Call GetFiles("\\?\C:\test with spaces") 'attach "\\?\" at the beginning for long folder path names! ex..'GetFiles("\\?\INSERT..." 'can also list multiple "Call GetFiles("\\?\[insert new folder path here]")" to list multiple folder paths all at once
End Sub
Sub GetFiles(ByVal path As String)
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")
Dim folder As Object
Set folder = FSO.GetFolder(path)
Dim SubFolder As Object
Dim file As Object
For Each SubFolder In folder.Subfolders
GetFiles (SubFolder.path)
Next SubFolder
Range("A1") = "parent folder"
'Range("A1").Offset(0, 1) = "FILE/FOLDER PATH"
Range("A1").Offset(0, 3) = "FILE or FOLDER"
Range("A1").Offset(0, 4) = "DATE CREATED"
Range("A1").Offset(0, 5) = "DATE MODIFIED"
Range("A1").Offset(0, 6) = "SIZE"
Range("A1").Offset(0, 7) = "TYPE"
Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = Replace(folder, "\\?\", "")
Range("A" & Rows.Count).End(xlUp).Offset(0, 1) = Replace(folder, "\\?\", "")
Range("A" & Rows.Count).End(xlUp).Offset(0, 2) = folder.Name
Range("A" & Rows.Count).End(xlUp).Offset(0, 3) = "FOLDER"
Range("A" & Rows.Count).End(xlUp).Offset(0, 4) = folder.datecreated
Range("A" & Rows.Count).End(xlUp).Offset(0, 5) = folder.DateLastModified
'For Each SubFolder In folder.Subfolders
'Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = Replace(subfolder.path, "\\?\", "")
'Range("A" & Rows.Count).End(xlUp).Offset(0, 1) = Replace(folder, "\\?\", "")
'Range("A" & Rows.Count).End(xlUp).Offset(0, 2) = subfolder.Name
'Range("A" & Rows.Count).End(xlUp).Offset(0, 3) = "FOLDER"
'Range("A" & Rows.Count).End(xlUp).Offset(0, 4) = subfolder.datecreated
'Range("A" & Rows.Count).End(xlUp).Offset(0, 5) = subfolder.DateLastModified
'Next SubFolder
'For Each file In folder.Files
'Range("A" & Rows.Count).End(xlUp).Offset(1, 0) = Replace(file.path, "\\?\", "")
'Range("A" & Rows.Count).End(xlUp).Offset(0, 1) = Replace(folder, "\\?\", "")
'Range("A" & Rows.Count).End(xlUp).Offset(0, 2) = file.Name
'Range("A" & Rows.Count).End(xlUp).Offset(0, 3) = "FILE"
'Range("A" & Rows.Count).End(xlUp).Offset(0, 4) = file.datecreated
'Range("A" & Rows.Count).End(xlUp).Offset(0, 5) = file.DateLastModified
'Range("A" & Rows.Count).End(xlUp).Offset(0, 6) = file.Size
'Range("A" & Rows.Count).End(xlUp).Offset(0, 7) = file.Type
'Next file
With Range("E:F")
.NumberFormat = "dddd mmmm dd, yyyy H:mm:ss AM/PM" 'long file date and time
End With
Set FSO = Nothing
Set folder = Nothing
Set SubFolder = Nothing
Set file = Nothing
End Sub
Bookmarks