Home > 类库下载 > C# class library > C# method to read specific files in a folder

C# method to read specific files in a folder

高洛峰
Release: 2016-10-14 17:05:41
Original
1699 people have browsed it

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);
}
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template