What would be the fastest way to search for a file programtically in C#. I know the relative location of the file, lets say its "abcd\efgh\test.txt". I also know that this file is on my E:\ drive. “abcd” is a subdirectory on some directory in E:\ drive.
Thanks
Since you know the root directory you want to search and a string pattern for a filename, you can create a DirectoryInfo with the root directory:
And then call
GetFiles()to get all the matches. PassingSearchOption.AllDirectorieswill ensure the search is recursive.Or if you know part of the path (instead of the filename):
And then you can navigate to the file from there.