Find a file with a certain extension in folder

后端 未结 6 1963
清歌不尽
清歌不尽 2020-11-27 15:10

Given a folder path (like C:\\Random Folder), how can I find a file in it that holds a certain extension, like txt? I assume I\'ll have to do a sea

6条回答
  •  Happy的楠姐
    2020-11-27 15:31

    Look at the System.IO.Directory class and the static method GetFiles. It has an overload that accepts a path and a search pattern. Example:

     string[] files = System.IO.Directory.GetFiles(path, "*.txt");
    

提交回复
热议问题