1、递归获取目录下的所有文件清单
调用:
List<string> fileList = GetFileList(path);
方法
private static List<string> GetFileList(string path) { List<string> fileList = new List<string>(); if (Directory.Exists(path) == true) { foreach (string file in Directory.GetFiles(path)) { fileList.Add(file); } foreach (string directory in Directory.GetDirectories(path)) { fileList.AddRange(GetFileList(directory)); } } return fileList; }
2、非递归获取目录下的文件清单
static List<string> fileList1 = new List<string>(); private static void GetFileList1(string path) { if (Directory.Exists(path) == true) { foreach (string file in Directory.GetFiles(path)) { fileList1.Add(file); } foreach (string directory in Directory.GetDirectories(path)) { GetFileList1(directory); } } }
原文:http://www.cnblogs.com/xiaoduo/p/4444920.html