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
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,710 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
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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