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
Bookmarks