简体   繁体   中英

How to list all the folders and sub folders in a directory without using recursion

请告诉我如何编写程序以列出目录中的所有文件夹和子文件夹,而无需使用递归和任何库函数。(在C#中)?

var dirList = Directory.GetDirectories("directotyPath", "*", SearchOption.AllDirectories);

这将返回给定directotyPath中的所有目录。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM