Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 366
Nitkov Avatar asked Oct 14 '13 06:10

Nitkov


1 Answers

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.

like image 150
Baldrick Avatar answered Oct 05 '22 04:10

Baldrick