📄 unzip.cs
字号:
using System;
using System.Text;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Runtime.Serialization.Formatters.Binary;
using System.Data;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.GZip;
namespace Compression
{
public class Unzip
{
public void UnZipFile(string ZipFileName, string UnzipPath)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(ZipFileName));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = UnzipPath;
string fileName = ZipFileName;
//生成解压目录
Directory.CreateDirectory(directoryName);
if (fileName != String.Empty)
{
//解压文件到指定的目录
string entryPath = theEntry.Name;
if(entryPath.Substring(1, 1) == ":")
{
entryPath = entryPath.Substring(2);
}
string path = GetFilePath(directoryName + entryPath.Replace(@"\\", @"\"));
Directory.CreateDirectory(path);
FileStream streamWriter = File.Create(directoryName + entryPath.Replace(@"\\", @"\"));
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
s.Close();
}
private string GetFilePath(string FileName)
{
string[] strs = FileName.Split('\\');
string Path = "";
for(int i = 0; i < strs.Length - 1; i++)
{
Path += strs[i] + "\\";
}
if(Path == "")
{
return @"c:\";
}
return Path;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -