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?
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...
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;
也许我在这里遗漏了一些东西,但为什么不将进度条的最大值分配给pending.Count
并在每次处理文件时将进度条的值加1?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.