You can go without implementing recursion, because recursive search is already provided using the optional parameter
System.IO.SearchOption.AllDirectories
:
System.IO.Directory.GetFiles(
path, searchPattern, System.IO.SearchOption.AllDirectories);
System.IO.Directory.GetDirectories(
path, searchPattern, System.IO.SearchOption.AllDirectories);
The above usage is all you need to know.
There is one caveat though, related to the
searchPattern
parameter. Please see this discussion:
Directory.Get.Files search pattern problem[
^]. At first, I did a mistake, too. All credit goes to Abhishek Sur and DaveyM69.
—SA