Since you know the root directory you want to find and the string pattern for the file name, you can create DirectoryInfo with the root directory:
DirectoryInfo dir = new DirectoryInfo(@"E:\");
And then call GetFiles()to get all matches. Passing SearchOption.AllDirectoriesensures that the search is recursive.
List<FileInfo> matches =
new List<FileInfo>(dir.GetFiles(partialFilename,
SearchOption.AllDirectories));
Or, if you know part of the path (instead of the file name):
List<DirectoryInfo> matches =
new List<DirectoryInfo>(dir.GetDirectories(partialDirectoryName,
SearchOption.AllDirectories));
And then you can go to the file from there.
source
share