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,816 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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