如何递归地列出在C#中的一个目录中的所有文件? [英] How to recursively list all the files in a directory in C#?

查看:190
本文介绍了如何递归地列出在C#中的一个目录中的所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何递归列出在C#中的目录和子目录中的所有文件?

How to recursively list all the files in a directory and child directories in C#?

推荐答案

的文章涵盖了所有你需要的。除相对于搜索的文件和比较名称,只是打印出来的名称

This article covers all you need. Except as opposed to searching the files and comparing names, just print out the names.

可以修改,像这样:

   static void DirSearch(string sDir)
   {
       try
       {
           foreach (string d in Directory.GetDirectories(sDir))
           {
               foreach (string f in Directory.GetFiles(d))
               {
                   Console.WriteLine(f);
               }
               DirSearch(d);
           }
       }
       catch (System.Exception excpt)
       {
           Console.WriteLine(excpt.Message);
       }
   }

这篇关于如何递归地列出在C#中的一个目录中的所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆