Results 1 to 6 of 6
Hey guys !
You know, I've been working hard the whole day trying to figure out
one damn system-call or library function that could tell me the
accurate size of ...
- 05-03-2008 #1Just Joined!
- Join Date
- Mar 2008
- Location
- India
- Posts
- 30
Find directory-size through C ??? LINUX ???
Hey guys !
You know, I've been working hard the whole day trying to figure out
one damn system-call or library function that could tell me the
accurate size of any directory (with its contents) anywhere in a
filesystem.
Believe me, I've pestered every book, web-page, and any reference
on Linux programming that I could.
And I now have an idea that there actually isn't any such library
function or method (IN C/C++).
Also, so far as I know, a directory's size is NOT simply a summation of its constituent files.
So, can you please help me calculate the directory-size through a pseudo
code or a ready-made C code (I'll kiss you for that! (on your head)).
HELP !!!
- 05-03-2008 #2
Kisses or no, you can get the size of the directory itself (not including its constituent files) by calling stat() on the directory and multiplying together the st_blksize and st_blocks fields of the resultant struct stat.
You can do exactly the same thing for each of the constituent files. If any of those is a directory, do the same thing for each of its constituent files, and so on.
Then add it all up.
As I'm sure you know by now, opendir(), readdir() (the one in section 3 of the man pages, not section 2), and closedir() are what you use to step through a directory. Skip the . and .. entries in each directory.
I won't waste my time or insult your intelligence by actually writing the code, but that ought to be all you need.
I just got a kiss from my wife (on the head), so that about wraps this up!
Hope this helps.--
Bill
Old age and treachery will overcome youth and skill.
- 05-03-2008 #3Just Joined!
- Join Date
- Mar 2008
- Location
- India
- Posts
- 30
Thanks Bill !
You're a nice pal.
- 05-03-2008 #4
Not sure if this is what your looking for, but try:
du -a directoryname
- 05-04-2008 #5Just Joined!
- Join Date
- Mar 2008
- Location
- India
- Posts
- 30
- 04-08-2009 #6Just Joined!
- Join Date
- Apr 2009
- Posts
- 1


Reply With Quote
