There are loads of questions and answers about how to get the size of a directory - recursively summing the length of the files - easy.
However all the answers I've seen are incomplete. Where you recursively iterate over a volume there are directories that throw exceptions - UnauthorizedAccessException
for example. I've also noticed in Win 7 there are paths that exceed 260 characters, which throws a PathTooLongException
.
All of which means, in C# at least, you cannot scan a C:\ drive and get a real figure back for the size of the volume because you have to skip any directory or file that throws an exception.
I am looking for a way of getting a proper, true, accurate figure for bytes stored on disk for a given directory. I don't care if I have to go low level and write some C++, or call the Win APIs.
How can this be achieved? Thanks.