Quicker (quickest?) way to get number of files in a directory with over 200,000 files

前端 未结 10 1417
Happy的楠姐
Happy的楠姐 2021-02-04 07:35

I have some directories containing test data, typically over 200,000 small (~4k) files per directory.

I am using the following C# code to get the number of files in a di

10条回答
  •  一生所求
    2021-02-04 08:04

    FYI, .NET 4 includes a new method, Directory.EnumerateFiles, that does exactly what you need is awesome. Chances are you're not using .NET 4, but it's worth remembering anyway!

    Edit: I now realise that the OP wanted the NUMBER of files. However, this method is so useful I'm keeping this post here.

提交回复
热议问题