根据指定目录获取所以文件包括子目录下的文件
/// <summary> /// 获取目录中所有文件包含子目录中的文件 /// </summary> /// <param name="path"></param> /// <returns></returns> private List<string> GetAllFiles(string path) { List<string> list = GetFiles(path); foreach (string dir in Directory.GetDirectories(path)) { if (Directory.GetDirectories(dir).Length > 0) list.AddRange(GetAllFiles(dir)); else list.AddRange(GetFiles(dir)); } return list; } /// <summary> /// 获取文件 /// </summary> /// <param name="path"></param> /// <returns></returns> private List<string> GetFiles(string path) { List<string> files = new List<string>(); foreach (string file in Directory.GetFiles(path, "*.*")) { files.Add(file); } return files; }