Question

How to implement a progress bar for files searching? On present time, i have done this :

string[] allFoundFiles = Directory.GetFiles(@folderPath, "*.jpg", SearchOption.AllDirectories);

It search and record files with jpg-extension, but how to remake it to implement progress bar for files searching?

Was it helpful?

Solution

There is no way I know of to do it automaticly, however I would suggest breaking up the search in parts so that you can estimate. See the following SO Post for details:

updating progress bar during a file search

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.

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.

Essetially you will be able to estimate the % complete based on the sum of directories searched and the sum of all directories.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top