4

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.

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
MalcomTucker
  • 7,407
  • 14
  • 72
  • 93

1 Answers1

2

Is not going to be easy but it can be done and while I am not sure that you can overcome the permissions issues essentially what you have to do is go on a lower level and read the NTFS master file table directly as shown in this wonderful piece of code shared by this caring developer who got the idea from another such developer.

Here is a reference that will help you. Google 'NTFS architecture' or design for more specs. And please share some of your work & research:) It will be helpful to many

Edit: Another project which may help you. After testing it says that it supports only NTFS 3.0 or higher.

user1416420
  • 498
  • 2
  • 7