【发布时间】:2018-05-21 21:41:34
【问题描述】:
我正在尝试读取可以或不能放在文件夹中的文本文件的内容,我正在使用 DotNetZip 库来实现这一点
结构是这样的
条件一:
ZipFile/Folder(any name)/List of TXT Files.
条件二:
ZipFile/List of TXT Files.
所有文本文件都有一行数字数据,看起来像这样。
ABC.txt
1000232
1212154
4454457
我还需要在 DataTable 的单个列中列出所有 TXT 文件中的这些数字
这是我到目前为止所尝试的。
string pathtoZip = pathtotheZipfile;
using (var zip = ZipFile.Read(pathtoZip))
{
int totalEntries = zip.Entries.Count;
ZipEntry e = null;
foreach (ZipEntry f in zip.Entries)
{
if (f.FileName.Contains("/"))
{
e = f;
break;
}
}
if (e.IsDirectory && e != null)
{
}
else
{
foreach (ZipEntry g in zip.Entries)
{
}
}
}
用于将文本文件转换为数据表
public DataTable TexttoDataTable(string NewFilePath)
{
DataTable dt = new DataTable();
var lines = File.ReadAllLines(NewFilePath);
dt.Columns.Add();
for (int i = 1; i < lines.Count(); i++)
{
DataRow dr = dt.NewRow();
string[] values = lines[i].Split(new char[] { ' ' });
if (values.Length<=1)
{
values = lines[i].Split(new char[] { ',' });
}
for (int j = 0; j < values.Count(); j++)
dr[j] = values[j];
dt.Rows.Add(dr);
}
return dt;
}
Zip 只能有一个文件夹,但文件夹名称可以不同。
【问题讨论】:
-
你的问题是......有人填空了吗?还是您有特定的编译器或运行时错误要解决?