I have the following code:
List<string> result = new List<string>();
foreach (string file in Directory.EnumerateFiles(path,"*.*",
SearchOption.AllDirectories)
.Where(s => s.EndsWith(".mp3") || s.EndsWith(".wma")))
{
result.Add(file);
}
It works fine and does what I need. Except for one small thing. I would like to find a better way to filter on multiple extensions. I would like to use a string array with filters such as this:
string[] extensions = { "*.mp3", "*.wma", "*.mp4", "*.wav" };
What is the most efficient way to do this using NET Framework 4.0/LINQ? Any suggestions?
I'd appreciate any help being an occasional programmer :-)
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…