1 string path="指定路徑"; 2 3 string filename =「須要查找的文件名.csv"; 4 5 List<string> lineStringList = new List<string>();//存儲全部讀取到的文件 6 7 DirectoryInfo[] dateDirArr = new DirectoryInfo(path).GetDirectories(); //取指定路徑下的全部目錄 8 9 foreach (DirectoryInfo directoryInfo in dateDirArr) 10 11 { 12 string fullName = filePath + directoryInfo.Name + "\\" + filename; 13 if (!File.Exists(fullName)) 14 { 15 continue;//目錄下不存在此文件,返回。 16 } 17 FileInfo file = new FileInfo(fullName); 18 StreamReader reader = new StreamReader(file.FullName); 19 while (!reader.EndOfStream)//判斷是否讀取完成 20 { 21 lineStringList.Add(reader.ReadLine()); 22 } 23 reader.Close(); 24 25 }