+ Reply to Thread
Results 1 to 1 of 1

how to add exclude folder paths list to main code

Hybrid View

  1. #1
    Registered User
    Join Date
    01-01-2014
    Location
    toronto
    MS-Off Ver
    Excel 365
    Posts
    47

    how to add exclude folder paths list to main code

    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
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 12-29-2015, 04:19 AM
  2. Showing only folder paths in long list of URLs
    By comicb in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-31-2015, 10:06 PM
  3. VBA code to get list of files from multiple paths
    By sn152 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2015, 08:09 AM
  4. list subfolders and files of main folder with details
    By buerere in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-21-2014, 10:44 AM
  5. Not sure this is possible with folder paths and macros
    By jh51745 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-13-2014, 08:27 PM
  6. Replies: 1
    Last Post: 03-28-2013, 02:49 PM
  7. Improvement - Option To Nest Folders as Sub Folder Under a Main Folder / Heading
    By :) Sixthsense :) in forum Suggestions for Improvement
    Replies: 4
    Last Post: 01-28-2013, 07:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1