天天看点

c#获取文件夹指定的多种类型的文件

//遍历本文件夹中的文件及子文件夹中的文件:
/*newpath = Directory.GetFiles(newsecpath, "*.*",
                    SearchOption.AllDirectories).Where(s => s.EndsWith(".png") || s.EndsWith(".jpg")
                    || s.EndsWith(".ico")).ToArray();*/
//仅遍历本文件夹中的文件:
newpath = Directory.GetFiles(newsecpath, "*.*",
                    SearchOption.TopDirectoryOnly).Where(s => s.EndsWith(".png") || s.EndsWith(".jpg")
                    || s.EndsWith(".ico")).ToArray();