• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#递归查找文件夹下所有文件和子文件夹的所有文件

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
    1. 方法实现
    2. public class DirectoryAllFiles  
    3.    {  
    4.        static List<FileInformation> FileList = new List<FileInformation>();  
    5.        public static List<FileInformation> GetAllFiles(DirectoryInfo dir)  
    6.        {  
    7.            FileInfo[] allFile = dir.GetFiles();  
    8.            foreach (FileInfo fi in allFile)  
    9.            {  
    10.                FileList.Add(new FileInformation{ FileName=fi.Name,FilePath=fi.FullName });  
    11.            }  
    12.            DirectoryInfo[] allDir= dir.GetDirectories();  
    13.            foreach (DirectoryInfo d in allDir)  
    14.            {  
    15.                GetAllFiles(d);  
    16.            }  
    17.            return FileList;  
    18.        }  
    19.    }  
    20.   
    21.    public class FileInformation  
    22.    {  
    23.        public string FileName { get; set; }  
    24.        public string FilePath { get; set; }  
    25.    }  
    26. 方法调用:
    27. List<FileInformation> list = DirectoryAllFiles.GetAllFiles(

new System.IO.DirectoryInfo(@"E:\Test"));  if (list.Where(t => t.FileName.ToLower().Contains("json")).Any()) Console.WriteLine("有信息");  foreach (var item in list)  

    {     
                  Console.WriteLine(

string.Format("文件名:{0}---文件目录{1}",item.FileName,item.FilePath));  

    }  

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c#实体类生成工具发布时间:2022-07-13
下一篇:
C# 异步编程 异步委托调用同步方法发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap