Exact file extension match with GetFiles()?

前端 未结 8 760
温柔的废话
温柔的废话 2020-12-11 04:55

I\'d like to retrieve a list of files whose extensions match a specified string exactly.

DirectoryInfo di = new DirectoryInfo(someValidPath);
List

        
8条回答
  •  天命终不由人
    2020-12-11 05:23

    DirectoryInfo di = new DirectoryInfo(someValidPath);
    List myFiles = new List();
    foreach (FileInfo fi in di.GetFiles("*.txt"))
    {
       if (fi.Extension == ".txt")
          myFiles.Add(fi);
    }
    

提交回复
热议问题