Dr Lovegrove wrote:

Ah, the progress bars, yes.. They show the traversal through the scan. The top one is the root directory, the next one is each folder in the root, then the third is each item in that folder. Usually it's
just the top two which are useful, but it depends on the structure of
your collection. If you had say two directories 'flacs' and 'mp3s' in
your root, the 2nd progress bar would probably be more use as the
first would only be at 0% or 50%.. I know it's a bit confusing, but
it saves doing a pre-scan just to work out how many files, etc..

You can do a one-pass tree traversal on a single progress bar using the following pseudocode algorithm:

updateProgressBar(0.0);
traverseDir(rootDir, 0.0, 1.0);

traverseDir(dir, start, dirTarget) {
    children[] = dir.getChildren();
    sharePerChild = (dirTarget - start)/children.size();
    current = start;
    for each child in children[] {
        if(child.isDirectory()) {
            traverseDir(dir, current, current+sharePerChild);
        } else {
            processFile(child);
        }
        current += sharePerChild;
        updateProgressBar(current);
    }
}

It won't move the progress bar a uniform amount for each file, but assuming a fairly uniform distribution of files in the directory tree, it should behave rationally.

- Marc
_______________________________________________
Discuss mailing list
[email protected]
http://lists.slimdevices.com/lists/listinfo/discuss

Reply via email to