Solved

VB.Net - A fast way to find folder size or number of files in a folder/sub folders

Posted on 2013-01-01
2
2,930 Views
Last Modified: 2013-01-02
Hi Experts.  I am writting a program that iterates through very large folders (100G to 500G) and I need to be able to show the progress of the program.   To do that I first need a fast way to get either the size of the folder or the number of files in the folder.   So this way I guage the progress and show it.      

A short wait while the process prepares itself would be OK for the user, but iterating through the folder is impractical as the program does this anyway and it takes too long.    

I see scripting has a way to do it quickly but I understand this is frowned upon in VB.Net.

It must of course include all sub folders

As Windows seems to have this data available anyway, perhaps there is a way to access this quickly?

Many thanks
0
Comment
Question by:PNRT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 250 total points
ID: 38734596
Unfortunately .NET doesn't have a good way to calculate directory sizes. Windows does this the same way you are doing it, by iterating through all the files. You can try using Directory.GetFiles with the SearchOption.AllDirectories but that might be a bit flaky.

I think your best bet might be to spawn a worker thread and do the calculation there. That way you can update the UI when the calculation is done without making the user wait for it.
0
 
LVL 9

Assisted Solution

by:sognoct
sognoct earned 250 total points
ID: 38734763
from this article :
http://www.codeproject.com/Articles/38959/A-Faster-Directory-Enumerator

And as  Russ_Suter correctly says also filesystem takes the exact time of
 Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Length

So count files and add a counter in the worker, give progressbar1.maximumvalue the number of files and assign progressbar1.value the current counter value.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question