Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProgressBar when Scanning a Hard Drive

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:\\");
    }
}
like image 723
Brian Avatar asked Jan 27 '09 16:01

Brian


People also ask

Does progressbar95 have a hard drive?

Solid State Hybrid Drive, or SSHDs, which don't exist in Progressbar95, store the OS on a small SSD and have a larger HDD for file storage. When the game is completed:

How do I scan a hard drive using the error checking tool?

Right-click or tap and hold a drive to check. Select Properties > Tools > Check > Scan drive. Wait for the scan to complete. Follow any instructions given. You may be instructed to restart. This article explains how to scan a hard drive using the Error Checking tool in Windows 10 and Windows 8. Variations for Windows 7, Vista, and XP are included.

How do I scan a hard drive in Windows 10?

Right-click or tap and hold a drive to check. Select Properties > Tools > Check > Scan drive. Wait for the scan to complete. Follow any instructions given. You may be instructed to restart. This article explains how to scan a hard drive using the Error Checking tool in Windows 10 and Windows 8.

How to fix Windows 10 scanning and repairing hard drive?

Step 1: Launch your Windows 10 File Explorer and Click on "This PC". Step 2: Right-click on the hard drive that Windows is scanning and repairing and select Properties. The hard drive might be available as F, E, or any drive letter you have set.


3 Answers

If you need to make a progress bar and you can't spare the time it takes to gather accurate information, then you're not going to be able to make a perfect progress bar. With that assumption in mind, you can still make a progress bar that isn't completely inaccurate.

For example, you make a function that subdivides the progress bar depending on the number of subdirectories in the current directory. So if your root directory has 10 subdirectories, allocate 10% of the progress bar to each of those directories. Then, enter into the first subdirectory and count its subdirectories. If it has 5, allocate 20% of the first 10% of the progress bar to each of those (2% of the total progress bar). Continue like this until you reach a directory with no subdirectories, do your processing there and increase the progress bar whatever fractional amount it represents.

Each % on the progress bar won't represent the same amount of work done by the algorithm, but given your contraints I doubt you can do much better.

like image 141
Welbog Avatar answered Oct 13 '22 15:10

Welbog


Just don't use it. Try something more appropriate like spinning animation or Kitts style bar: http://en.wikipedia.org/wiki/KITT.

like image 29
Jacek Ławrynowicz Avatar answered Oct 13 '22 16:10

Jacek Ławrynowicz


You can do it in a few ways....a simple process that might not be 100% accurate.

Before you start, get a count of files, then use that to calculate the percentage of completion, after processing X files update the progress. Granted there is a performance cost of the lookup. Maybe just get a count of root directories, and as you traverse update the progress.

Another option might be to simply record a count of "last run" details, and use that to calculate a percentage, again, not necessarily 100% accurate, but an option.

I guess a few other things that come to mind is to simply show the user a "in progress" dialog and not even try to get a percentage. Otherwise, maybe just show the current working directory, showing that you are making progress.

like image 39
Mitchel Sellers Avatar answered Oct 13 '22 15:10

Mitchel Sellers