【发布时间】:2017-03-04 07:05:31
【问题描述】:
string path = "C:\\BSD";
string extension = Console.ReadLine();
List<string> allExstensions = getAllExtention(); // Is there a method where I get all File Extensions : *.png, *.txt,.......
if (!allExstensions.Contains(extension))
throw new Exception("The Extension you wrote does not exist!!");
foreach (string directory in Directory.GetDirectories(path))
{
foreach (string file in Directory.GetFiles(directory,extension))
{
Console.WriteLine(file);
}
}
有没有办法检查enterf exstention是否存在?
【问题讨论】:
-
不,文件可以有任意扩展名或根本没有。有一个“注册”扩展的概念,但是你不需要注册一个文件扩展来使用它。
-
你想达到什么目的?您认为哪些扩展有效?你的问题很不清楚。