C# – Directory.GetFiles with SearchOption or recursive search when searching directory tree

cdirectorynetrecursionsubdirectory

When searching for files in a directory tree ( Folder and all sub-folders), what is the effective difference between doing this:

Directory.GetFiles(root, "*", SearchOption.AllDirectories);

and doing your own recursive search using

Directory.GetFiles(root) and Directory.GetDirectories(root)

What are the pros and cons for using each method, which method is suited for which use case?
Thanks.

Best Answer

The main reason you might want to 'roll your own' recursion in this case could be that you want to be able to set up custom progress updating / notification to users during a long file search.

This isn't possible if you hand everything over to the framework method from the start.