Find number of files with a specific extension, in all subdirectories

前端 未结 7 1855
执念已碎
执念已碎 2020-12-03 07:16

Is there a way to find the number of files of a specific type without having to loop through all results inn a Directory.GetFiles() or similar method? I am looking for somet

7条回答
  •  伪装坚强ぢ
    2020-12-03 08:09

    You can use this overload of GetFiles:

    Directory.GetFiles Method (String, String, SearchOption)

    and this member of SearchOption:

    AllDirectories - Includes the current directory and all the subdirectories in a search operation. This option includes reparse points like mounted drives and symbolic links in the search.

    GetFiles returns an array of string so you can just get the Length which is the number of files found.

提交回复
热议问题