-1

Directory.GetDirectories returns only the given path's sub-directories but I would like to list all the subs, and their subs all the way to the end.

I'm thinking of a recursive function, but I am not sure how to approach the problem.

Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
Kaan Demirel
  • 180
  • 1
  • 2
  • 16

2 Answers2

2

Use another Directory.GetDirectories overload.

string[] dirs = Directory.GetDirectories(@"c:\data", "*", SearchOption.AllDirectories);
Hamid Pourjam
  • 20,441
  • 9
  • 58
  • 74
1

Here is how:

new DirectoryInfo(Assembly.GetExecutingAssembly().Location /* or any other location */)
.EnumerateDirectories("*"/*or any other pattern*/,SearchOption.AllDirectories);

You can modify all arguments as needed.

Ognyan Dimitrov
  • 6,026
  • 1
  • 48
  • 70