Exact file extension match with GetFiles()?

前端 未结 8 776
温柔的废话
温柔的废话 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:28

    Try this:

    DirectoryInfo di = new DirectoryInfo(someValidPath); 
    List myFiles =  
        (
            from file in di.GetFiles("*.txt")
            where file.Extension == ".txt"
            select file
        ).ToList();
    

提交回复
热议问题