views:

132

answers:

4

hi,

Anyone knows other way to get a directoy's size, than calculate it's size by counting file with file? I'm interested on some win32 API function. I've google it about this, but i didn't found relevant information so i'm asking here.

Best regards,

PS: I know how to calculate a directory size by using findfirst and findnext and sum all file's size.

+1  A: 

If you already know how to do another level, just use recursion to get every level. As your function traverses the current directory, if it comes across subdirectory, call the function recursively to get the size of that subdirectory.

Marcelo Cantos
thank you, but i've already said that i need some api function if exist.
Radu Barbu
+2  A: 

I don't think there's an API for this. I don't think Windows knows the answer. i.e. it would have to recursively search the tree and summarize each folder, using the technique that Marcelo indicated.
If there were such an API call available, then other things would use it too and Windows would be able to immediately tell you folder sizes.

Chris Thornton
+1 for "other things would use it too".
Cosmin Prund
yhea...you're right +1
Radu Barbu
+2  A: 

Getting the size of one directory is a pretty big problem, mostly because it's something you can't define. Examples of problems:

  • Some filesystems, including NTFS and most filesystems on Linux support the notion of "hard links". That is, the very same file may show up in multiple places. Soft links (reparse points) pose the same problem.
  • Windows allows mounting of file systems to directories. Example: "C:\DriveD" might be the same thing as "D:\".
  • Do you want the file size on disk or the actual size of the file?
  • Do you care about actual DIRECTORY entries? They also take up space!
  • What do you do with files you don't have access to? Or directories you don't have permission to browse? Do you count those?

Taking all this into account means the only possible implementation is a recursive implementation. You can write your own or hope you find a ready-written one, but the end performance would be the same.

Cosmin Prund
1) don't care about those...i'll parse only fadirectories2) same as 13) actual size4) no, i need the size of files inside the folder5) will be installed with "super admin" rightsI understand. so the only solution is to use my own....ok, thanks everybodybest regards,
Radu Barbu
+1 for the answer. http://blogs.msdn.com/b/oldnewthing/archive/2004/12/28/336219.aspx
Alexander
+1  A: 

You can use FindFile component. It will recursive the directories for you.

http://www.delphiarea.com/products/delphi-components/findfile/

Ted Stephens