How do I find out how many files are in a directory?

后端 未结 4 772
名媛妹妹
名媛妹妹 2020-12-19 00:20

I need to get a count of the number of files in a directory. I could get the names of all the files in the directory using System.IO.Directory.GetFiles() and t

4条回答
  •  我在风中等你
    2020-12-19 01:01

    I don't believe so, no - at least not in vanilla .NET. I suspect it's not the actual fetching of the names that takes the time - it's the OS walking through the directory internals. There may be a Win32 call you could make via P/Invoke.

    How large is the directory you're looking at? In general it's at least traditionally not been a good idea to have more than a few hundred files in a directory. File systems have improved at this in general, but I don't know what the current state is with NTFS and Fat32.

提交回复
热议问题