读取文件夹下的所有文件

string path="指定路径";

string filename =“需要查找的文件名.csv";

List<string> lineStringList = new List<string>();//存储所有读取到的文件

DirectoryInfo[] dateDirArr = new DirectoryInfo(path).GetDirectories(); //取指定路径下的所有目录

foreach (DirectoryInfo directoryInfo in dateDirArr)

{
string fullName = filePath + directoryInfo.Name + "\\" + filename;
if (!File.Exists(fullName))
{
continue;//目录下不存在此文件,返回。
}
FileInfo file = new FileInfo(fullName);
StreamReader reader = new StreamReader(file.FullName);
while (!reader.EndOfStream)//判断是否读取完成
{
lineStringList.Add(reader.ReadLine());
}
reader.Close();

}

posted @ 2019-06-12 14:50  厦门哈韩  阅读(248)  评论(0编辑  收藏  举报