By another question about the maximum number of files in a folder, I noticed that
DirectoryInfo.GetFiles().Length
is returning a System.In32, but the Maximum value of a Int32 is
2.147.483.647 (Int32.MaxValue)
while on NTFS (an many other filesystems) the maximum number of files can go far beyond that.
on NTFS it is
4.294.967.295 single files in one folder (probably an Uint32)
Which leads me to the interesting question:
Is it possible to get the number of files in a folder on NTFS with the .NET framework, when the number of files exceeds the Int32.MaxValue, in an elegant and performing manner?
note: this is not a matter of why. and I know, those are a lot of files ;)
There is a LongLength
property on Array
, which returns the length as a long
. Anyway, if GetFiles
returns more than Int32.MaxValue
items, you will have problems anyway... like an OutOfMemoryException
;)
When you don't actually need the number of items, I suggest you use the EnumerateFiles
method instead (introduced in 4.0). It doesn't fetch all the filenames in memory at once, instead it fetches them one by one
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With