做一个能够以文件夹为单位提取txt内容的winform,求助!

speedfishman 2010-09-21 11:14:42
如题,老板刚刚布置了一个任务,利用winform来实现,求助高手!
可以从本地用选取文件夹,文件夹中会有几十个txt文件,每个txt文件中有一些行。
这些行是如下格式:
<event logger="root" timestamp="2010-09-08T09:31:02.2798250+08:00" level="INFO" thread="7432"
<event logger="root" timestamp="2098-09-08T09:31:06.0767000+08:00" level="ERROR" thread="7432"
<event logger="root" timestamp="2010-09-08T09:31:06.1079500+08:00" level="WARN" thread="7432"

现在需要把整个文件夹中含有Error的行提取出来,显示在listbox当中,然后统计一下一共多少这种行。

求大侠相助。给思路和代码,越详细越好!
...全文
114 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
speedfishman 2010-09-21
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ajq1989 的回复:]
FolderBrowserDialog
[/Quote]
然后呢?怎么把通过FolderBrowserDialog选到的文件夹地址传到DirectoryInfo dif = new DirectoryInfo("路径")这个路径中呢??
ajq1989 2010-09-21
  • 打赏
  • 举报
回复
FolderBrowserDialog
speedfishman 2010-09-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wuyq11 的回复:]
DirectoryInfo dif = new DirectoryInfo("路径");
foreach(FileInfo f in dif.GetFiles("*.txt"))
{
foreach(string string s in File.ReadAllLines(""))
{//Contains("Error")或regex判断,count获取数据
或var result =……
[/Quote]

路径不是固定的,而是用户自己可以从本地选的。怎么弄呢?用什么控件呢
wuyq11 2010-09-21
  • 打赏
  • 举报
回复
DirectoryInfo dif = new DirectoryInfo("路径");
foreach(FileInfo f in dif.GetFiles("*.txt"))
{
foreach(string string s in File.ReadAllLines(""))
{//Contains("Error")或regex判断,count获取数据
或var result = from q in File.ReadAllLines("") where q.Contains("Error") select q;
}
}
linwanhai 2010-09-21
  • 打赏
  • 举报
回复

ListBox lb = new ListBox();
DirectoryInfo dif = new DirectoryInfo("路径");
foreach(FileInfo f in dif.GetFiles("*.txt"))
{
string[] ss = File.ReadAllLines(f.FullName);
for (int i = 0; i < ss.Length; i++)
{
if (ss[i].ToUpper().Contains("ERROR"))
{
lb.Items.Add(ss[i]);
}
}
}
kj289907795 2010-09-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ajq1989 的回复:]
选择文件夹。
遍历文件夹下的文件。 过滤 txt文件
依次打开txt文件。
读取行,判断是否包含error.添加至list
最后list.count 可以知道多少行。
[/Quote]
+1
ajq1989 2010-09-21
  • 打赏
  • 举报
回复
选择文件夹。
遍历文件夹下的文件。 过滤 txt文件
依次打开txt文件。
读取行,判断是否包含error.添加至list
最后list.count 可以知道多少行。
speedfishman 2010-09-21
  • 打赏
  • 举报
回复
大侠们,麻烦give a hand啊

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧