So, I am doing a simple check to get a list of all the folders on the hard drive (c: \ windows and c: \ windows \ system32 are treated as separate entries). If I wanted to provide a progress bar for this 1-2 minute task, how would I do it? That is, I know how to make a progressbar, but I donโt know how to determine what part of the work for it is done.
Edit: Please note that performing a preliminary scan is NOT a solution, as this scan only receives a list of folders, and a preliminary scan will take the same amount of time.
An example code is given below. It takes less than 2 minutes, but less than 10 seconds, to work on my system for a second time due to disk access caching. I created options based on stacks, not recursion.
One of the mechanisms that I found is probably not 100% reliable, but much faster than my scan, to pass "dir / s / ab / b" to my program and count newline instances. Dir does some magic that scans my HD much better than my program, but I donโt know what magic it is.
class Program
{
static void recurse(string pos)
{
DirectoryInfo f = new DirectoryInfo(pos);
try
{
foreach (DirectoryInfo x in f.GetDirectories("*"))
{
recurse(x.FullName);
}
} catch (Exception) {}
}
static void Main(string[] args)
{
recurse("c:\\");
}
}
Brian source
share