Skip to content

Instantly share code, notes, and snippets.

@akilab
Created June 21, 2020 13:16
Show Gist options
  • Select an option

  • Save akilab/d66bf9b56b9d0e1146b8e3bc16e587b3 to your computer and use it in GitHub Desktop.

Select an option

Save akilab/d66bf9b56b9d0e1146b8e3bc16e587b3 to your computer and use it in GitHub Desktop.
ZIPファイル内のテキストを読み込む
using System;
using System.IO;
using System.IO.Compression;
namespace ZipReader
{
internal class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello");
string zipPath = "xxxxx.zip";
using (ZipArchive e = ZipFile.Open(zipPath, ZipArchiveMode.Read))
{
foreach (ZipArchiveEntry entry in e.Entries)
{
if (entry.Name.Contains(".csv"))
{
Console.WriteLine(entry.Name);
using (var sr = new StreamReader(entry.Open()))
{
int num = 1;
string line;
sr.ReadLine();//1行目スキップ
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine("{0}:{1}", num, line);
num++;
}
}
}
}
}
}
}
}
@akilab
Copy link
Author

akilab commented Jun 21, 2020

Zipファイル内のテキストを検索する

ZIP内部が、フォルダで階層構造になっていても関係なく
e.Entriesでファイルを順次処理できる。
ZIP構造あまりわかっていない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment