Sub openFile()
Dim foldersToSearchForGivenFile AsString() = {"D:\iDevelop\SDKs\Any SDK\source", "D:\TEST_DIRECTORY"} ' Enter here the directories to search for given file . you can enter any number of directories
Dim fileToOpen AsString = InputBox("Enter the name of the file(with extension) to open", "Open File ", ".cpp")
IfString.IsNullOrEmpty(fileToOpen) Then
Return
EndIf
' Searches given file in current project/solution
Dim projItem As EnvDTE.ProjectItem = DTE.Solution.FindProjectItem(fileToOpen)
If not projItem IsNothingThen
projItem.Open()
Return
EndIf
'If the given file is not found in current project/solution it is searched inside given directories
Dim fileExt AsString = fileToOpen.Substring(fileToOpen.LastIndexOf(".") + 1)
Dim directory AsString
For Each directory In foldersToSearchForGivenFile
Dim listofFiles AsString() = System.IO.Directory.GetFiles(directory, "*." + fileExt, IO.SearchOption.AllDirectories)
Dim filePath AsString
Dim fileName AsString
For Each filePath In listofFiles
fileName = filePath.Substring(filePath.LastIndexOf("\") + 1)
If (fileName.Equals(fileToOpen)) Then
ExecuteCommand("open", """" + filePath + """")
Return
EndIf
Next
Next
MsgBox("The specified file - " + fileToOpen + " - could not be found")
EndSub