public void Director(string dir, List<string> list) { DirectoryInfo d = new DirectoryInfo(dir); FileInfo[] files = d.GetFiles();//文件 DirectoryInfo[] directs = d.GetDirectories();//文件夹 foreach (FileInfo f in files) { list.Add(f.Name);//添加文件名到列表中 } //获取子文件夹内的文件列表,递归遍历 foreach (DirectoryInfo dd in directs) { Director(dd.FullName, list); } }