12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace ToolsClassLibrary
- {
- /// <summary>
- ///
- /// </summary>
- public static class CsvDirectoryConfigMassage
- {
- /// <summary>
- /// 将指定目录下CSV文件进行读取,格式List<文件名,List<测点编号>>
- /// </summary>
- /// <param name="path">装载CSV文件的目录</param>
- /// <param name="errString">错误描述</param>
- /// <returns></returns>
- public static Dictionary<string, List<string>> GetCsvAndId(string path, out string errString)
- {
- Dictionary<string, List<string>> config = new Dictionary<string, List<string>>();
- errString = "";
- try
- {
- string dir = path;
- if (Directory.Exists(dir) == false)//如果不存在就创建file文件夹
- {
- Console.WriteLine("缺失配置文件夹csvfiles。");
- errString = "缺失配置文件夹csvfiles。";
- }
- string[] files = Directory.GetFiles(dir);
- foreach (string file in files)
- {
- if (file.LastIndexOf(".csv") > -1)
- {
- CsvStreamReader Cr = new CsvStreamReader(file);
- if (Cr.ColCount >= 1 && Cr.RowCount > 0)
- {
- config.Add(file, new List<string>());
- for (int i = 1; i <= Cr.RowCount; i++)
- {
- //Console.WriteLine(Cr.ColCount);
- config[file].Add(Cr[i, 1]);
- //config[file].Add(Cr[i, 2]);
- //config[file].Add(Cr[i, 3]);
- }
- }
- }
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message.ToString());
- errString = e.Message.ToString();
- }
- return config;
- }
- }
- }
|