-2

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?

Dmitry
  • 13,797
  • 6
  • 32
  • 48
  • 1
    "*How to realize*"?? I am not sure what you mean – huMpty duMpty Mar 27 '14 at 18:11
  • It seems what your asking is how to get the progress of the search and tie that to a progress bar. If that is in fact your intent please elaborate your question a bit. – Gent Mar 27 '14 at 18:12
  • what type of project are you working on? (WinForms, Windows 8 Apps, Silverlight...) – Pierre Mar 27 '14 at 18:12
  • you might want to use [EnumerateFiles](http://msdn.microsoft.com/en-us/library/system.io.directory.enumeratefiles(v=vs.110).aspx) instead. This would give you an enumerable. However, you'll have to have some heuristic for the percentage, i.e. counting all subdirectories first and dividing the progress percentage into equal parts per subdirectory – Dmitry Ledentsov Mar 27 '14 at 18:13
  • 2
    @huMptyduMpty It's quite obvious from the context of the question that he's looking for how to do it. Don't be pedantic, a lot of users don't speak english as well as you might. – tnw Mar 27 '14 at 18:23
  • Yes, I am from Russia and I don't very good speak English. – user3242084 Mar 27 '14 at 18:27

1 Answers1

1

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.

Community
  • 1
  • 1
Gent
  • 2,675
  • 1
  • 24
  • 34
  • 1
    Nicely done… thank you for enhancing it. Not sure who down-voted your answer, but you certainly got my up-vote on this one. – e-sushi Mar 27 '14 at 18:50