Community
Hi
I am trying to search through a folder and all subsequent subfolders for a file matching a certain name.
I am having trouble getting this to work.
Here is the section of my code doing the searching. I keep getting a type mismatch on the 12th line
'Recursvly check all folders and subfolders for file matching BKT UID
'NOTE!! tools/Reference/'microsoft scripting runtime' must be ticked!!
Private Sub Recurse(oAsmPath As String, bktUID As String)
Dim FSO As New FileSystemObject
Dim myFolder As Folder
Dim mySubFolder As Folder
Dim myFile As File
Set myFolder = FSO.GetFolder(oAsmPath)
For Each mySubFolder In myFolder.SubFolders
For Each myFile In mySubFolder.Files
If InStr(myFile.Name, bktUID) <> 0 Then
Debug.Print myFile.Name & " in " & myFile.Path
Exit For
End If
Next
oAsmPath = mySubFolder.Path
Call Recurse(oAsmPath, bktUID)
Next
End Sub
I am not very experienced at programming at all so any help would be appreciated cheers!
Hi Jd, this is my solution.
Private Sub Recurse(oAsmPath As String, bktUID As String) Dim FSO As New FileSystemObject Dim myFolder As Folder Dim mySubFolder As Folder Dim myFile 'As File Set myFolder = FSO.GetFolder(oAsmPath) For Each mySubFolder In myFolder.SubFolders For Each myFile In mySubFolder.Files 'If InStr(Ucase(myFile.Name), Ucase(bktUID)) <> 0 Then 'not case sensitive as an example If InStr(myFile.Name, bktUID) <> 0 Then Debug.Print myFile.Name & " in " & myFile.Path Exit For End If Next oAsmPath = mySubFolder.Path Call Recurse(oAsmPath, bktUID) Next End Sub
Hi Jd, have you found a solution?
Bregs
Rossano Praderi