搜索文件期间更新进度条 [英] updating progress bar during a file search

查看:175
本文介绍了搜索文件期间更新进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这<一href="http://stackoverflow.com/questions/724148/is-there-a-faster-way-to-scan-through-a-directory-recursively-in-net/724184#724184">question提供了一种快速的方式来使用 kernel.dll 递归查找文件属性,如:文件名。问题是报告进展情况(如在Windows窗体应用程序)被限制在哪个文件或目录是目前因为它没有信息总文件数的前期。

This question provides a fast way to use the kernel.dll to recursively find file attributes, e.g. file names. The problem is reporting progress (such as in a Windows Forms App) is limited to which file or directory it is currently on as it has no information as to total file count upfront.

不过,我知道,在Windows 7中,如果您使用文件资源管理器搜索文件时,它显示了搜索的进度条:

Though, I know in Windows 7 if you use the file explorer to search for a file, it shows a progress bar for the search:

那么它是如何他们这样做吗?是总文件数在这里提前知道?是否有可能模仿这种进步从上面链接的问题的答案报告?我不知道怎么做,没有一个总的文件数的前期。

So how is it they do it here? Is total file count known here ahead of time? Is it possible to mimic this kind of progress reporting in the answer from the question linked above? I'm not sure how to do it without a total file count upfront.

我能找到的最接近的问题是这个似乎有有些问题,这个递归方法,因为我没有文件夹数前期和行为会非常奇怪,许多文件的一个目录。

The closest question I could find was this one which seems to have some problems with this recursion method as I don't have folder count upfront, and the behavior would be very odd for a single directory of many files.

推荐答案

根据您精确需要得到,有可能是一个简单的两通液(不是最佳的网络驱动器,所以你可能需要调整有)

Depending on how accurate you need to get, there may be a simple two-pass solution (not optimal for network drives, so you may need to tune there).

N 级别的目录(比如4,包括驱动器),计数子目录的数目。这通常是一个快捷的操作,但你可以把它调整到只有递归多的时候说5子目录present或相似。保存此号码。

For the first n levels of directories (say 4, including drive), count the number of sub-directories. This is typically a quick operation, although you can tweak it to only recurse when more than say 5 subdirectories are present or similar. Store this number.

当你执行真正的搜索,是在是n 步骤根的子目录中,你已经完成的一些跟踪。使用该号码和所存储的计数值来估计完成

As you perform the real search, keep track of the number of subdirectories you've completed that are within n steps of the root. Use this number and the stored count to estimate completion.

例如,具有基本的结构:

For example, with the basic structure:

C:\
    a\
        1\
            i\
            ii\
            iii\
        2\
        3\
    b\
    c\

计数的 1 的,忽略的的兄弟姐妹,计数的 2 的,等等。然后,当搜寻,增加吧,当你完成搜索的 3 2 1 的,等等。

Count a, 1, ignore i and siblings, count 2, etc. Then, while searching, increase the bar when you finish searching 3, 2, 1, a, etc.

现在,这绝对不是傻瓜式的证明。有可能是竞争状态,它不是非常准确,以及各种其他的事情。

Now, this is absolutely not fool-proof. There may be race conditions, it's not terribly accurate, and all sorts of other things.

然而,对于一个低粒度进度条,它足够近,它会出现pretty的准确。更重要的是从用户体验的角度来看,使用存储的计数和比较反对这种进步往往prevent酒吧从整个过程中间不断增长。

However, for a low-granularity progress bar, it's close enough that it will appear pretty accurate. More importantly from a user-experience perspective, using a stored count and comparing progress against that tends to prevent the bar from growing halfway through the process.

我实际使用这种技术在某些code的这里

I'm actually using this technique in some code here.

在建设初期,其下降10水平,仍然是pretty的迅速。我不记得到底有多少测试走进它,但(尽管只是检查时间提前1 / 1/1000)到2.5-3亿个文件进行搜索时,酒吧是明显准确无误许多停顿。请注意,你的短进度条,更准确就会出现。 ;)

The initial build, which goes down 10 levels, is still pretty speedy. I don't remember just how much testing went into it, but the bar is visibly accurate without many pauses when searching through 2.5-3 million files (despite only checking 1/1000th of that ahead of time). Note that the shorter your progress bar, the more accurate it will appear. ;)

这篇关于搜索文件期间更新进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆