Reputation: 1069
I want to write a simple function, which is to check is there a file in specified dictionary which should use recursive way to check
The function is simple, but my code looks stupid.
Can you help me to refine the code a little bit more beautiful...
private bool SearchFileInFolder(string baseURL, string fileName)
{
bool result = true;
List<string> dictionaries = new List<string>(Directory.GetDirectories(baseURL));
foreach (string dic in dictionaries)
{
if (File.Exists(dic + Path.DirectorySeparatorChar + fileName))
result = false;
else
result = SearchFileInFolder(dic, fileName);
}
return result;
}
Can I use Parallel.ForEach to make the function more efficient ? But the function is a recursive function, so ....
Upvotes: 0
Views: 98
Reputation: 13399
You can use this overloaded method:
public static string[] GetFiles(
string path,
string searchPattern,
SearchOption searchOption
)
You can give the option to search in all subdirectories, that way you don't need to do it manually.
Upvotes: 4