public class UnitTest1 { [Fact] public void Test1() { List<string> array = new List<string>(); DirectoryInfo theFolder = new DirectoryInfo(@"G:检验批测试"); DirectoryInfo[] dirInfo = theFolder.GetDirectories(); //遍历文件夹 foreach (DirectoryInfo NextFolder in dirInfo) { // this.listBox1.Items.Add(NextFolder.Name); FileInfo[] fileInfo = NextFolder.GetFiles(); foreach (FileInfo NextFile in fileInfo) //遍历文件 array.Add(NextFile.Name); } } }