ProgressBar when scanning a hard drive

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:\\");
    }
}
+5
source share
7 answers

, , , , , , . .

, , (, , , 150 , 10 , 15 - ).

- ( , ) . , - , (, 5 , 3- ), , , . , , . , , - , .. - , . , -, , ( ) .

0

, , , . , .

, , . , 10 , 10% . . 5, 20% 10% (2% ). , , , .

% , , , , , .

+8

... , 100% .

, , , , X . , . , , , , .

" " , , 100% , .

, , , - "in progress" . , , , , .

+1

stdoutput "dir/ad/b/s c:/" . . , .

+1

Maximum Value. Maximum, 100, , , 1, , , ...

         Maximum    Value 
Tick1:    101          1   - 1% 
Tick2:    102          2   - 2%
Tick3:    103          3   - 3% 
TickN:    100+n        n 
Finish    100+n      100+n - 100%  --> force to fill the progress bar

, .

0

Catchwa. 14000, . , , . . , , . , . , Qt:

emit findProgressBar_setRange(14000); ... if (dir.size()) { m_dirsAtDepth[++m_depth] = dir.size(); } else { qreal product = 1.00; for (int i = 1; i <= m_depth; ++i) { product *= m_dirsAtDepth[i]; } int x = qRound((1.00 / product) * 14000); emit findProgressBar_addValue(x); }

. , , .

0

All Articles