Results 1 to 5 of 5

Find a folder by its name or wildcard (revisit)

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-10-2008
    Location
    Austin
    Posts
    660

    Find a folder by its name or wildcard (revisit)

    Hi all,

    Leith, had assisted in putting a function code together which searches a directory and
    and its sub directory for specified sub-directory for the given root path:
    L:\Global\Elec Dept Projects\

    With the use of a userforms combobox list of subfolders, I have the option to add a specific subfolder to the root path:

    L:\Global\Elec Dept Projects\Ready\
    Where (Ready) is a Status Folder which will holder a several job folders(aka 4WL - Project)

    If my filter includes a search word like : 4WL and I specify a subfolder (Ready), then the following function works like a charm.

    However, if a don't include a subfolder or allow my filter to be (*) then I run into problems.

    When I try to search by a folder name or partial name (*4WL*) just using the root path
    I will get an overstack error

    If I run using no filter word, just the (*) and the root, I get the root directory path returned along with the status folder paths, all listed mutiple times. No job folder paths will be returned.

    
    
    Function MapFolders(DirPath As String, Optional Filter As String, Optional Cnt As Long) As Long
    'Written: April 21, 2010
    'Updated: May 17, 2010
    'Author:  Leith Ross
    'Summary: Creates a list of all folders and all their subfolders. This list is stored
    '         in a public array called "FolderList". The macro returns the number of folders
    '         matching the filter. If no filter is specified then all folders are returned.
    'Dim FolderList() As Variant
    
    
      Dim FSO As Object
      Dim Folder As Object
        
        If FSO Is Nothing Then
           Set FSO = CreateObject("Scripting.FileSystemObject")
        End If
        
       ' DirPath = "L:\Global\Elec Dept Projects\"
        If Filter = "" Then Filter = "*"
        
         'On Error Resume Next
          For Each Folder In FSO.GetFolder(DirPath).subfolders  '& SubFolders)
            If Folder.Name Like Filter Then
               ReDim Preserve FolderList(Cnt)
               FolderList(Cnt) = Folder.Path
               Cnt = UBound(FolderList) + 1
            End If
            If Folder.subfolders.Count > 0 Then
               MapFolders Folder.Path, Filter, Cnt
            End If
          Next Folder
          
        MapFolders = Cnt
      
        If OptionButton1 = True And Cnt > 0 Then
          ListBox1.List = WorksheetFunction.Transpose(FolderList)
        End If
        
        Set FSO = Nothing
       
    End Function
    I've been trying to figure out whats causing this issue for quite some time and still have yet to resolve this issue. If anyone, "Leith" or anyone else knows exactly whats causing this issue and can assist in resolving it, I'd be most grateful for the help.

    Source:
    http://www.excelforum.com/excel-prog...-wildcard.html

    Thanks,

    BDB
    Last edited by bdb1974; 09-07-2011 at 12:55 PM.

Thread Information

Users Browsing this Thread

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

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