首页 > 其他 > 详细

C#遍历目录下的文件和子目录

时间:2014-02-25 23:44:33      阅读:462      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1         //打开目录
 2         private void BtnClickOpenDirPics(object sender, EventArgs e)
 3         {
 4             FolderBrowserDialog DirPics = new FolderBrowserDialog();
 5             DirPics.SelectedPath = "D:\\";
 6 
 7             if (DirPics.ShowDialog() == DialogResult.OK)
 8             {
 9                 string FolderPathName = DirPics.SelectedPath;
10                 DirectoryInfo DiFolder = new DirectoryInfo(FolderPathName);
11                 ArrayList Lfiles = new ArrayList();
12                 GetAll(DiFolder, ref Lfiles);
14             }
15         }
16 
17         private void GetAll(DirectoryInfo dir, ref ArrayList FileList)//搜索文件夹中的文件
18         {
19             FileInfo[] allFile = dir.GetFiles();
20             foreach (FileInfo fi in allFile)
21             {
22                 FileList.Add(fi.FullName);
23             }
24 
25             DirectoryInfo[] allDir = dir.GetDirectories();
26             foreach (DirectoryInfo d in allDir)
27             {
28                 GetAll(d, ref FileList);
29             }
30         }
bubuko.com,布布扣

C#遍历目录下的文件和子目录

原文:http://www.cnblogs.com/autumoonchina/p/3566590.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!