Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update progress bar while iterating file structure

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?

like image 235
user1775334 Avatar asked Nov 12 '22 19:11

user1775334


1 Answers

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...

like image 90
Gianluca Ghettini Avatar answered Nov 15 '22 11:11

Gianluca Ghettini