日期:2014-05-18  浏览次数:20451 次

100分请教解压缩问题
如何用程序把一个压缩包解压到当前目录。
      比如说/sample.rar文件程序解压的时候不是解压到sample文件夹里,而是直接解压到/下面。

------解决方案--------------------
/// <summary>
/// 根据传输的参数进行压缩处理
/// 这个参数为 string [] length=2
/// 1:待压缩文件目录
/// 2:压缩后的目标文件
/// 修改内容:将压缩后的文件内部的全部路径转换为相对路径
/// 修改时间:2006-01-19
/// </summary>
/// <param name= "args "> 1:待压缩文件目录 2:压缩后的目标文件 </param>
public void ZipFileMain(string[] args)
{
string[] filenames = Directory.GetFiles(args[0]);
Crc32 crc = new Crc32();
ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));
s.SetLevel(6); // 0 - store only to 9 - means best compression
foreach (string file in filenames)
{
FileStream fs = File.OpenRead(file);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
//如何将全部路径转换为 相对路径 就是一个文件的名字
//注释 修改 2007-01-05
string strTempFile = file.Split( '\\ ')[file.Split( '\\ ').Length - 1];
//------------------------------------------------
//LZ 看这里 这里可以将你的“sample”加近来

ZipEntry entry = new ZipEntry(strTempFile);
entry.DateTime = DateTime.Now;
entry.Size = fs.Length;
fs.Close();

crc.Reset();
crc.Update(buffer);

entry.Crc = crc.Value;
//将所有的entry文件路径更改为文件名
s.PutNextEntry(entry);

s.Write(buffer, 0, buffer.Length);
}
s.Finish();
s.Close();
}
}
------解决方案--------------------
如果是把一个sample文件夹压缩呢
------解决方案--------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Diagnostics;
public partial class _Default : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
//清清月儿 http://blog.csdn.net/21aspnet/
}
protected void Button1_Click(object sender, EventArgs e)
...{
//压缩
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
...{
the_Reg = Registry.ClassesRoot.OpenSubKey( "Applications\WinRAR.exe\Shell\Open\Command ");
the_Obj = the_Reg.GetValue( " ");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " a " + " 1.rar " + " " + "C:\1\1.txt ";
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = "C:\1 ";//获取或设置要启动的进程的初始目录。
the_Proce