public image[] getImages() { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { try { ///根據路徑實例化一個對象 var dirInfo = new System.IO.DirectoryInfo(fbd.SelectedPath); ///選出所有符合一定後綴的文件列表,此處選擇的是圖像文件 mySelectedImages = dirInfo.GetFiles("*.*", System.IO.SearchOption.AllDirectories) .Where(info => IsRight(info)).ToArray(); } catch (Exception ex) { LogHelper.LogError(ex); } } } private bool IsRight(System.IO.FileInfo info) { //選擇的文件後綴名 List<string> patterns = new List<string>() { ".png", ".jpg", ".bmp", ".tif" }; return patterns.Contains(info.Extension); }