Please tell me how to write program to list all the folders and subfolders in a directory without using recursion and any library functions.(in C#)?
Asked
Active
Viewed 88 times
0
-
Use a stack as illustrated in the StackBasedIteration example here: https://msdn.microsoft.com/en-us/library/bb513869.aspx – Alex K. Jan 05 '17 at 10:30
2 Answers
0
var dirList = Directory.GetDirectories("directotyPath", "*", SearchOption.AllDirectories);
This will return all directories in the given directotyPath
.

Sagar
- 454
- 10
- 22
-
This is originally what I posted as a comment, but see above where he asks for it in a way that doesn't use library functions. – ColinM Jan 05 '17 at 11:20
0
Stack or queue both can be used with searching algorithms for such purpose if you don't want to list all directories using recursion.
Here is demonstration of your requirement using stack. The solution is in Java, you can understand the work flow and convert it to c#
by yourself

Community
- 1
- 1

CodeGenius
- 514
- 1
- 6
- 21