110,534
社区成员
发帖
与我相关
我的任务
分享
public class UnZipClass
{
public void UnZip(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(args[1]);
string fileName = Path.GetFileName(theEntry.Name);
//生成解压目录
Directory.CreateDirectory(directoryName);
if (fileName != String.Empty)
{
//解压文件到指定的目录
FileStream streamWriter = File.Create(args[1] + theEntry.Name);
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();
}
}
string strtxtPath = "C:\\freezip\\free.txt";
string strzipPath = "C:\\freezip\\free.zip";
System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
Process1.StartInfo.FileName = "Winrar.exe";
Process1.StartInfo.CreateNoWindow = true;
//// 1
////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
////到c:\freezip\free.rar
//strzipPath = "C:\\freezip\\free";//默认压缩方式为 .rar
//Process1.StartInfo.Arguments = " a -r " + strzipPath + " " + strtxtPath;
//// 2
////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
////到c:\freezip\free.rar
//strzipPath = "C:\\freezip\\free";//设置压缩方式为 .zip
//Process1.StartInfo.Arguments = " a -afzip " + strzipPath + " " + strtxtPath;
Process1.Start();
if (Process1.HasExited)
{
int iExitCode = Process1.ExitCode;
if (iExitCode == 0)
{
Response.Write(iExitCode.ToString() + " 正常完成");
}
else
{
Response.Write(iExitCode.ToString() + " 有错完成");
}
}