Hi,

How to get directory size?
Recursive alogrithm take more time for calculating directory size.
so I don't like search a recursive algorithm.
Any other method

Recommended Answers

All 3 Replies

What do you mean? Find the number of files in a directory? Find the total size of files in a directory?

I don't like search a recursive algorithm.

It would be the algorithm I would choose anyways.

What do you mean? Find the number of files in a directory? Find the total size of files in a directory?


I called this function recursively for calculate the directory size.

struct stat filedetails = this->GetFileStat(fileName);
filesize = myStat.st_size;

It wil take more time.
I am trying another method.
Anybody any ideas........

Traversing the subdirectory tree is the only way, if that is what you're after.

Think about how file systems are implemented?
If you have /path/to/some/directory, does it make sense to update /path/to/some, /path/to, /path and finally / every time you add/delete/change a file in some sub-directory?

Sure, it gives you a nice easy answer, and the other 99% of the time you're cursing this horribly slow file system!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.