[color=Green] ''' -----------------------------------------------------------------------------
''' <summary>
''' Determines whether the specified file exists in the specified folder or any subfolder.
''' </summary>
''' <param name="folderName">
''' The fully qualified path of the root folder to search, e.g. "C:\MyFolder".
''' </param>
''' <param name="fileName">
''' The name of the file to search for, e.g. "MyFile.txt"
''' </param>
''' <returns>
''' True if the file is found;
''' False otherwise.
''' </returns>
''' -----------------------------------------------------------------------------
[/color] [color=Blue]Private Function[/color] IsFileInFolder([color=Blue]ByVal[/color] folderName [color=Blue]As String[/color], [color=Blue]ByVal[/color] fileName [color=Blue]As String[/color]) [color=Blue]As Boolean[/color]
[color=Blue]If[/color] IO.File.Exists(folderName & IO.Path.DirectorySeparatorChar & fileName) [color=Blue]Then[/color]
[color=Green]'The file exists in this folder.[/color]
[color=Blue]Return True[/color]
[color=Blue]End If[/color]
[color=Green]'Get an array of subfolders.[/color]
[color=Blue]Dim[/color] subfolderNames [color=Blue]As String[/color]() = IO.Directory.GetDirectories(folderName)
[color=Green]'Search each subfolder.[/color]
[color=Blue]For Each[/color] subfolderName [color=Blue]As String In[/color] subfolderNames
[color=Blue]If Me[/color].IsFileInFolder(subfolderName, fileName) [color=Blue]Then[/color]
[color=Green]'The specified subfolder, or one of its subfolders, contains the file.[/color]
[color=Blue]Return True[/color]
[color=Blue]End If[/color]
[color=Blue]Next[/color]
[color=Green]'The file was not found.[/color]
[color=Blue]Return False[/color]
[color=Blue]End Function[/color]