Reputation: 191
I use this function, to search for all exe files in selected directory:
public static IEnumerable<string> GetFiles(string root, string searchPattern)
{
Stack<string> pending = new Stack<string>();
pending.Push(root);
while (pending.Count != 0)
{
var path = pending.Pop();
string[] next = null;
try
{
next = Directory.GetFiles(path, searchPattern);
}
catch { }
if (next != null && next.Length != 0)
foreach (var file in next) yield return file;
try
{
next = Directory.GetDirectories(path);
foreach (var subdir in next) pending.Push(subdir);
}
catch { }
}
}
How can I update the progress bar status, based on the number of files found?
Upvotes: 5
Views: 1339
Reputation: 133
Maybe I'm missing something here, but why don't you assign the Maximum of the progress bar to pending.Count
and add 1 to the progress bar's value each time you process a file?
Upvotes: 0
Reputation: 11628
The point is that you don't know the total number of exe files (aka the 100%) that you'll find so basically you CAN'T render a progress bar! For this kind of tasks it would be more suited an hourglass or a marquee bar...
Upvotes: 1
Reputation: 275
You would want to search through and then set the progressbar maximum to the number of files found.
You can assign a counter that assigns the value a = to # of files found then set
progressBar.Maximum = a;
Upvotes: 0