So, I'm doing a simple scan to get a list of all folders on a hard drive (c:\windows and c:\windows\system32 are considered separate entries). If I wanted to provide a progress bar for this 1-2 minute task, how would I do so? That is, I know how to make the progressbar but am not sure how to determine how much of the work for it is done.
Edit: Note that performing a prescan is NOT a solution, since this scan is only getting a list of folders and a prescan would take just as long.
Code Sample is below. It takes under 2 minutes to run clean on my system, but less than 10s to run a 2nd time due to disk access caching. I've created variations on this that are stack-based rather than recursion based.
One mechanism I've found that is probably not 100% reliable but is much faster than my scan is to pipe "dir/s/ab/b" to my program and count instances of newline. Dir does some sort of magic that does a much better job scanning my HD than my program, but I don't know what that magic 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:\\");
}
}