Reporting Progress on Directory.GetFiles

Viewed 2220

Is there a quick way to load in the fully qualified path to every file (that you have read access to) starting with a supplied root directory into say a string[]?

I saw System.IO.Directory.GetFiles, but you have to supply a filter before you're allowed to input the SearchOption.AllDirectories, so I tried:

string[] directoryList = Directory.GetFiles(RootPath, "*.*",
                                            SearchOption.AllDirectories);

Where RootPath is my valid, rooted directory. This seemed to work OK, except that it hung my windows form app up for a very long time when pointing it to a large directory/file structure of 29GB and a few hundred thousand files.

So I thought about threading it via a BackgroundWorker so that my GUI didn't appear locked up, but I'm not sure how I'd report progress for something like this for a ProgressBar since it's just one statement that's doing the loading and I've no information on the total number of files upfront, or the number it has processed already etc.

1 Answers
Related