回答編集履歴

1

追記

2016/06/19 09:18

投稿

catsforepaw
catsforepaw

スコア5938

test CHANGED
@@ -23,3 +23,119 @@
23
23
  stArrayData.Add(record);
24
24
 
25
25
  ```
26
+
27
+
28
+
29
+ ---
30
+
31
+ 追記
32
+
33
+ Form1のコードを載せます。★マークが追加・変更部分です。
34
+
35
+ ```C
36
+
37
+ public partial class Form1 : Form
38
+
39
+ {
40
+
41
+ public Form1()
42
+
43
+ {
44
+
45
+ InitializeComponent();
46
+
47
+ }
48
+
49
+
50
+
51
+ private void button1_Click(object sender, EventArgs e)
52
+
53
+ {
54
+
55
+ MessageBox.Show("処理を開始します");
56
+
57
+ ReadCsv();
58
+
59
+ }
60
+
61
+
62
+
63
+ public static List<string[]> stArrayData = new List<string[]>(); // ★
64
+
65
+
66
+
67
+ static void ReadCsv()
68
+
69
+ {
70
+
71
+ try
72
+
73
+ {
74
+
75
+ // csvファイルを開く
76
+
77
+ System.IO.DirectoryInfo dirPath =
78
+
79
+ new System.IO.DirectoryInfo(@"E:/Desktop/Study/StudyProject/IN/");
80
+
81
+ System.IO.FileInfo[] files =
82
+
83
+ dirPath.GetFiles("test_*.csv", System.IO.SearchOption.AllDirectories);
84
+
85
+
86
+
87
+ // 指定フォルダからCSVを取得し、配列に格納する。
88
+
89
+ foreach(System.IO.FileInfo filePath in files)
90
+
91
+ {
92
+
93
+ using(var readCsv = new System.IO.StreamReader(filePath.FullName))
94
+
95
+ {
96
+
97
+ //ヘッダを読み捨てる。
98
+
99
+ readCsv.ReadLine();
100
+
101
+ // ストリームの末尾まで繰り返す
102
+
103
+ while(!readCsv.EndOfStream)
104
+
105
+ {
106
+
107
+ // ファイルから一行読み込む
108
+
109
+ string line = readCsv.ReadLine();
110
+
111
+ // カンマ区切りで分割して配列に格納する
112
+
113
+ string[] record = line.Split(','); // ★
114
+
115
+ stArrayData.Add(record); // ★
116
+
117
+ }
118
+
119
+ }
120
+
121
+ }
122
+
123
+ }
124
+
125
+ catch(System.Exception e)
126
+
127
+ {
128
+
129
+ // ファイルを開くのに失敗したとき
130
+
131
+ MessageBox.Show(e.ToString());
132
+
133
+ }
134
+
135
+ }
136
+
137
+ }
138
+
139
+ ```
140
+
141
+