当前位置:编程学习 > C#/ASP.NET >>

C# 如何遍历一个文件夹下的所有txt文档,并显示出来

C# 如何遍历一个文件夹下的所有txt文档,并显示出来 C# 遍历 txt 文件 显示 

--------------------编程问答-------------------- 

 foreach (string filename in GetFiles("C:\\Path", "*.txt", SearchOption.SearchOption.AllDirectories))

Console.WriteLine(filename); 

--------------------编程问答-------------------- 

 foreach (string filename in GetFiles("C:\\Path", "*.txt", SearchOption.AllDirectories))

Console.WriteLine(filename);  

--------------------编程问答--------------------

引用 2 楼 caozhy 的回复:
foreach (string filename in GetFiles("C:\\Path", "*.txt", SearchOption.AllDirectories))
Console.WriteLine(filename);

遍历之后如果要显示所有文本文档中的数据,怎么写 

--------------------编程问答-------------------- 

 string filecontent = string.Join("\r\n", System.IO.File.ReadAllLines(filename)); 

--------------------编程问答--------------------

引用 4 楼 caozhy 的回复:
string filecontent = string.Join("\r\n", System.IO.File.ReadAllLines(filename));

按照文件名挨个读出 

--------------------编程问答-------------------- 

 相当初级了。

补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,