Directory file size calculation - how to make it faster?

Posted by Xinxua on Stack Overflow See other posts from Stack Overflow or by Xinxua
Published on 2010-06-05T06:34:26Z Indexed on 2010/06/05 6:42 UTC
Read the original article Hit count: 234

Filed under:
|
|
|
|

Using C#, I am finding the total size of a directory. The logic is this way : Get the files inside the folder. Sum up the total size. Find if there are sub directories. Then do a recursive search.

I tried one another way to do this too : Using FSO (obj.GetFolder(path).Size). There's not much of difference in time in both these approaches.

Now the problem is, I have tens of thousands of files in a particular folder and its taking like atleast 2 minute to find the folder size. Also, if I run the program again, it happens very quickly (5 secs). I think the windows is caching the file sizes.

Is there any way I can bring down the time taken when I run the program first time??

© Stack Overflow or respective owner

Related posts about c#

Related posts about Windows