I need code that searches through all sub folders in the C drive and when it it matches to a specified file it returns the file path. Any suggestions?
I am using the following code
Sub ChkFolder()
Dim fso, oFolder, oSubfolder, oFile, queue As Collection
Set fso = CreateObject("Scripting.FileSystemObject")
Set queue = New Collection
queue.Add fso.GetFolder("C:")
Do While queue.Count > 0
Set oFolder = queue(1)
queue.Remove 1 'dequeue
For Each oSubfolder In oFolder.SubFolders
queue.Add oSubfolder 'enqueue
If oSubfolder.Name = "file name I am looking for" Then
MsgBox ("File Found")
End If
Next oSubfolder
Loop
End Sub
I get the following error while following this code
Run-time erorr '70':
Permission Denied
Is there a way to bypass folders that I do not have permissions for?