-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZipUtil.cs
More file actions
52 lines (48 loc) · 1.5 KB
/
ZipUtil.cs
File metadata and controls
52 lines (48 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Text;
using Ionic.Zip;
namespace MetroUITest
{
class ZipUtil
{
/// <summary>
/// 压缩文件列表
/// </summary>
/// <param name="fileList">文件列表</param>
/// <param name="zipFileName">压缩包名称</param>
public static void ZipFile(List<string> fileList,string zipFileName)
{
using (ZipFile zip = new ZipFile())
{
zip.AddFiles(fileList,@"\");
zip.Save(zipFileName);
}
}
/// <summary>
/// 压缩单个文件
/// </summary>
/// <param name="fileName">文件路径</param>
/// <param name="zipFileName">压缩包名称</param>
public static void ZipFile(string fileName,string zipFileName)
{
using (ZipFile zip = new ZipFile())
{
zip.AddFile(fileName);
zip.Save(zipFileName);
}
}
/// <summary>
/// 解压缩包
/// </summary>
/// <param name="fileName">压缩包名称</param>
/// <param name="outDir">解压缩路径</param>
public static void UnzipFile(string fileName,string outDir)
{
using (ZipFile zip = new ZipFile(fileName))
{
zip.ExtractAll(outDir, ExtractExistingFileAction.OverwriteSilently);
}
}
}
}