基本信息
源码名称:遍历文件夹、文件批量提取txt 文件中的关键内容
源码大小:0.10M
文件格式:.rar
开发语言:C#
更新时间:2018-11-12
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
批量提取txt 文件中的关键内容,并生成保存到txt文件中:一个关键字的值再多个文件中都存在,需要按照关键字提取所以的文件中的值,并按照关键字保存值。适合初学者学历遍历文件夹、文件、提取文件内容
private void button1_Click(object sender, EventArgs e) { FolderBrowserDialog fold = new FolderBrowserDialog(); if (fold.ShowDialog() == DialogResult.OK) { getFile(fold.SelectedPath); } string[] band = new string[] { "RT_WCDMA_B01_PDET", "RT_WCDMA_B02_PDET", "RT_WCDMA_B05_PDET", "RT_WCDMA_B08_PDET" , "RT_LTE_B03_PDET","RT_LTE_B05_PDET","RT_LTE_B07_PDET","RT_LTE_B34_PDET","RT_LTE_B39_PDET", "RT_LTE_B40_PDET","RT_LTE_B41_PDET","RT_CDMA_BC0_PDET","RT_WCDMA_B04_PDET","RT_LTE_B20_PDET", "RT_LTE_B28L_PDET","RT_LTE_B28H_PDET"}; /* OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Multiselect = true; string fileName=null; string readLine = null; fileDialog.Title = "请选择文件"; fileDialog.Filter = "所有文件(*.*)|*.*"; if (fileDialog.ShowDialog() == DialogResult.OK) { fileName = fileDialog.FileName; textBox1.Text = fileName; MessageBox.Show("已选择文件:" fileName, "选择文件提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } */ foreach (string path in filePath) { foreach (string s in band) { string readLine; List<string> listValue = new List<string>(); StreamReader sr = new StreamReader(path.ToString(), Encoding.Default); while ((readLine = sr.ReadLine()) != null) { Regex r = new Regex(s); Match m = r.Match(readLine); if (m.Success) { string[] splitString = readLine.Split(new string[] { s }, StringSplitOptions.RemoveEmptyEntries); //*#bsn:7HB08A4011000437*#value:3499*#minThreshold:100*#maxThreshold:30000*#result:pass*#cycle:0*#errorCode:NA*#testTime:1970-01-01 03:44:19*# string[] splitstring1 = splitString[1].Split('*'); string[] splitstring2 = splitstring1[2].Split(':'); string value = splitstring2[1]; //string PcbSN = splitString[1].Substring(6, 16); listValue.Add(value); } } string strSavefileName = s ".txt"; StreamWriter sw = new StreamWriter(strSavefileName, true, Encoding.Default); foreach (string ss in listValue) { sw.WriteLine(ss); } sr.Close(); sw.Close(); } } MessageBox.Show("数据抓取完成,请在目录下查看txt 文件!"); }