How to collect all files in a Folder and its Subfolders that match a string

后端 未结 6 1040
野性不改
野性不改 2020-12-16 12:05

In C# how can I search through a Folder and its Subfolders to find files that match a string value. My string value could be \"ABC123\" and a matching file might be ABC123_

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 12:54

     DirectoryInfo di = new DirectoryInfo("c:/inetpub/wwwroot/demos");
     FileInfo[] rgFiles = di.GetFiles("*.aspx");
    

    you can pass in a second parameter for options. Also, you can use linq to filter the results even further.

    check here for MSDN documentation

提交回复
热议问题