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);
}
登录后复制