天天看點

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();