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

前端 未结 7 1849
执念已碎
执念已碎 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条回答
  •  -上瘾入骨i
    2020-12-03 08:12

    The slickest method woud be to use linq:

    var fileCount = (from file in Directory.EnumerateFiles(@"H:\iPod_Control\Music", "*.mp3", SearchOption.AllDirectories)
                        select file).Count();
    

提交回复
热议问题