質問編集履歴
5
プログラムが見にくかったので更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -48,7 +48,6 @@
|
|
48
48
|
listBox1.Items.Add(directry);
|
49
49
|
}
|
50
50
|
}
|
51
|
-
```
|
52
51
|
|
53
52
|
private void button1_Click(object sender, EventArgs e)
|
54
53
|
{
|
@@ -76,4 +75,5 @@
|
|
76
75
|
}
|
77
76
|
Task.WhenAll(task);
|
78
77
|
}
|
79
|
-
}
|
78
|
+
}
|
79
|
+
```
|
4
プログラムが見にくかったので更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,10 +16,11 @@
|
|
16
16
|

|
17
17
|
|
18
18
|
###C#
|
19
|
+
```C#
|
19
20
|
private void button2_Click(object sender, EventArgs e)
|
20
21
|
{
|
21
22
|
//FolderBrowserDialogクラスのインスタンスを作成
|
22
|
-
|
23
|
+
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
23
24
|
//上部に表示する説明テキストを指定する
|
24
25
|
fbd.Description = "フォルダを指定してください。";
|
25
26
|
//ルートフォルダを指定する
|
@@ -47,6 +48,7 @@
|
|
47
48
|
listBox1.Items.Add(directry);
|
48
49
|
}
|
49
50
|
}
|
51
|
+
```
|
50
52
|
|
51
53
|
private void button1_Click(object sender, EventArgs e)
|
52
54
|
{
|
3
プログラムが見にくかったので更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,71 +7,71 @@
|
|
7
7
|
###質問内容
|
8
8
|
一つのzipファイルに並列処理で複数のファイルを圧縮することはそもそも可能でしょうか?
|
9
9
|
|
10
|
+
###質問内容追加(20180716 12:47)
|
11
|
+
・zipファイル内にディレクトリができない
|
12
|
+
・並列で一つのzipファイルにアクセスする為例外発生
|
13
|
+
|
14
|
+
|
10
15
|
###画像
|
11
16
|

|
12
17
|
|
13
|
-
|
18
|
+
###C#
|
14
|
-
|
19
|
+
private void button2_Click(object sender, EventArgs e)
|
20
|
+
{
|
21
|
+
//FolderBrowserDialogクラスのインスタンスを作成
|
22
|
+
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
23
|
+
//上部に表示する説明テキストを指定する
|
24
|
+
fbd.Description = "フォルダを指定してください。";
|
25
|
+
//ルートフォルダを指定する
|
26
|
+
//デフォルトでDesktop
|
27
|
+
fbd.RootFolder = Environment.SpecialFolder.Desktop;
|
28
|
+
//最初に選択するフォルダを指定する
|
29
|
+
//RootFolder以下にあるフォルダである必要がある
|
30
|
+
fbd.SelectedPath = @"C:\Windows";
|
31
|
+
//ユーザーが新しいフォルダを作成できるようにする
|
32
|
+
//デフォルトでTrue
|
33
|
+
fbd.ShowNewFolderButton = true;
|
34
|
+
//ダイアログを表示する
|
35
|
+
if (fbd.ShowDialog(this) == DialogResult.OK)
|
36
|
+
{
|
37
|
+
//選択されたフォルダを表示する
|
38
|
+
Console.WriteLine(fbd.SelectedPath);
|
39
|
+
textBox1.Text = fbd.SelectedPath;
|
40
|
+
}
|
41
|
+
//ListBoxに一覧を表示する
|
42
|
+
listBox1.Items.Clear();
|
43
|
+
var directries = Directory.GetDirectories(fbd.SelectedPath);
|
44
|
+
foreach (var directry in directries)
|
15
45
|
{
|
16
|
-
//FolderBrowserDialogクラスのインスタンスを作成
|
17
|
-
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
18
|
-
|
19
|
-
//上部に表示する説明テキストを指定する
|
20
|
-
fbd.Description = "フォルダを指定してください。";
|
21
|
-
//ルートフォルダを指定する
|
22
|
-
//デフォルトでDesktop
|
23
|
-
fbd.RootFolder = Environment.SpecialFolder.Desktop;
|
24
|
-
//最初に選択するフォルダを指定する
|
25
|
-
//RootFolder以下にあるフォルダである必要がある
|
26
|
-
fbd.SelectedPath = @"C:\Windows";
|
27
|
-
//ユーザーが新しいフォルダを作成できるようにする
|
28
|
-
//デフォルトでTrue
|
29
|
-
fbd.ShowNewFolderButton = true;
|
30
|
-
|
31
|
-
//ダイアログを表示する
|
32
|
-
if (fbd.ShowDialog(this) == DialogResult.OK)
|
33
|
-
{
|
34
|
-
//選択されたフォルダを表示する
|
35
|
-
Console.WriteLine(fbd.SelectedPath);
|
36
|
-
textBox1.Text = fbd.SelectedPath;
|
37
|
-
}
|
38
|
-
|
39
|
-
//ListBoxに一覧を表示する
|
40
|
-
listBox1.Items.Clear();
|
41
|
-
var directries = Directory.GetDirectories(fbd.SelectedPath);
|
42
|
-
foreach (var directry in directries)
|
43
|
-
{
|
44
|
-
|
46
|
+
Console.WriteLine(directry);
|
45
|
-
|
47
|
+
listBox1.Items.Add(directry);
|
46
|
-
}
|
47
48
|
}
|
49
|
+
}
|
48
50
|
|
49
|
-
|
51
|
+
private void button1_Click(object sender, EventArgs e)
|
52
|
+
{
|
53
|
+
//デスクトップ
|
54
|
+
string zipFilePath = $@"{System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)}\test.zip";
|
55
|
+
//ZIP書庫を作成
|
56
|
+
ZipFile.CreateFromDirectory(listBox1.Items[0].ToString(), zipFilePath);
|
57
|
+
//ディレクトリ分タスクを生成する
|
58
|
+
List<Task<bool>> task = new List<Task<bool>>();
|
59
|
+
//読み取りと書き込みができるようにして、ZIP書庫を開く
|
60
|
+
using (ZipArchive ziparchive = ZipFile.Open(zipFilePath, ZipArchiveMode.Update))
|
61
|
+
{
|
62
|
+
foreach (var directry in listBox1.Items)
|
50
63
|
{
|
51
|
-
string zipFilePath = $@"{System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)}\test.zip";//デスクトップ
|
52
|
-
|
53
|
-
//ZIP書庫を作成
|
54
|
-
ZipFile.CreateFromDirectory(listBox1.Items[0].ToString(), zipFilePath);
|
55
|
-
|
56
|
-
//ディレクトリ分タスクを生成する
|
57
|
-
|
64
|
+
task.Add(Task<bool>.Run(() =>
|
58
|
-
|
59
|
-
//読み取りと書き込みができるようにして、ZIP書庫を開く
|
60
|
-
using (ZipArchive ziparchive = ZipFile.Open(zipFilePath, ZipArchiveMode.Update))
|
61
65
|
{
|
66
|
+
string[] fileList = Directory.GetFiles(directry.ToString(), "*", SearchOption.AllDirectories);
|
62
|
-
|
67
|
+
foreach (var file in fileList)
|
63
|
-
|
68
|
+
{
|
64
|
-
task.Add(Task<bool>.Run(() =>
|
65
|
-
{
|
66
|
-
string[] fileList = Directory.GetFiles(directry.ToString(), "*", SearchOption.AllDirectories);
|
67
|
-
foreach (var file in fileList)
|
68
|
-
{
|
69
|
-
|
69
|
+
Console.WriteLine(file);
|
70
|
-
|
70
|
+
ZipArchiveEntry x = ziparchive.CreateEntryFromFile(file, System.IO.Path.GetFileName(file));
|
71
|
-
|
71
|
+
}
|
72
|
-
|
72
|
+
return true;
|
73
|
-
|
73
|
+
}));
|
74
|
-
|
74
|
+
}
|
75
|
-
|
75
|
+
Task.WhenAll(task);
|
76
|
-
|
76
|
+
}
|
77
|
-
|
77
|
+
}
|
2
回答を受けて、作ってみました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,4 +5,73 @@
|
|
5
5
|
c#7.1 .net4.7 VS2017
|
6
6
|
|
7
7
|
###質問内容
|
8
|
-
一つのzipファイルに並列処理で複数のファイルを圧縮することはそもそも可能でしょうか?
|
8
|
+
一つのzipファイルに並列処理で複数のファイルを圧縮することはそもそも可能でしょうか?
|
9
|
+
|
10
|
+
###画像
|
11
|
+

|
12
|
+
|
13
|
+
```C#
|
14
|
+
private void button2_Click(object sender, EventArgs e)
|
15
|
+
{
|
16
|
+
//FolderBrowserDialogクラスのインスタンスを作成
|
17
|
+
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
18
|
+
|
19
|
+
//上部に表示する説明テキストを指定する
|
20
|
+
fbd.Description = "フォルダを指定してください。";
|
21
|
+
//ルートフォルダを指定する
|
22
|
+
//デフォルトでDesktop
|
23
|
+
fbd.RootFolder = Environment.SpecialFolder.Desktop;
|
24
|
+
//最初に選択するフォルダを指定する
|
25
|
+
//RootFolder以下にあるフォルダである必要がある
|
26
|
+
fbd.SelectedPath = @"C:\Windows";
|
27
|
+
//ユーザーが新しいフォルダを作成できるようにする
|
28
|
+
//デフォルトでTrue
|
29
|
+
fbd.ShowNewFolderButton = true;
|
30
|
+
|
31
|
+
//ダイアログを表示する
|
32
|
+
if (fbd.ShowDialog(this) == DialogResult.OK)
|
33
|
+
{
|
34
|
+
//選択されたフォルダを表示する
|
35
|
+
Console.WriteLine(fbd.SelectedPath);
|
36
|
+
textBox1.Text = fbd.SelectedPath;
|
37
|
+
}
|
38
|
+
|
39
|
+
//ListBoxに一覧を表示する
|
40
|
+
listBox1.Items.Clear();
|
41
|
+
var directries = Directory.GetDirectories(fbd.SelectedPath);
|
42
|
+
foreach (var directry in directries)
|
43
|
+
{
|
44
|
+
Console.WriteLine(directry);
|
45
|
+
listBox1.Items.Add(directry);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
private void button1_Click(object sender, EventArgs e)
|
50
|
+
{
|
51
|
+
string zipFilePath = $@"{System.Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)}\test.zip";//デスクトップ
|
52
|
+
|
53
|
+
//ZIP書庫を作成
|
54
|
+
ZipFile.CreateFromDirectory(listBox1.Items[0].ToString(), zipFilePath);
|
55
|
+
|
56
|
+
//ディレクトリ分タスクを生成する
|
57
|
+
List<Task<bool>> task = new List<Task<bool>>();
|
58
|
+
|
59
|
+
//読み取りと書き込みができるようにして、ZIP書庫を開く
|
60
|
+
using (ZipArchive ziparchive = ZipFile.Open(zipFilePath, ZipArchiveMode.Update))
|
61
|
+
{
|
62
|
+
foreach (var directry in listBox1.Items)
|
63
|
+
{
|
64
|
+
task.Add(Task<bool>.Run(() =>
|
65
|
+
{
|
66
|
+
string[] fileList = Directory.GetFiles(directry.ToString(), "*", SearchOption.AllDirectories);
|
67
|
+
foreach (var file in fileList)
|
68
|
+
{
|
69
|
+
Console.WriteLine(file);
|
70
|
+
ZipArchiveEntry x = ziparchive.CreateEntryFromFile(file, System.IO.Path.GetFileName(file));
|
71
|
+
}
|
72
|
+
return true;
|
73
|
+
}));
|
74
|
+
}
|
75
|
+
Task.WhenAll(task);
|
76
|
+
}
|
77
|
+
}```
|
1
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,4 +4,5 @@
|
|
4
4
|
###環境
|
5
5
|
c#7.1 .net4.7 VS2017
|
6
6
|
|
7
|
+
###質問内容
|
7
8
|
一つのzipファイルに並列処理で複数のファイルを圧縮することはそもそも可能でしょうか?
|