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_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
Response.Write( "压缩成功 ");
}
catch (Exception ex)
...{
Response.Write(ex.ToString());
}
}
protected void Button2_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 = " X " + " 1.rar " + " " + "C:\1 ";
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
Response.Write( "解压缩成功 ");
}
catch (Exception ex)
...{
Response.Write(ex.ToString());
}
}
}
[解决办法]
jf
[解决办法]
关注,学习..
[解决办法]
如果是把一个sample文件夹压缩,解压出来东西有一个文件夹sample
[解决办法]
//解压
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.FileName = "cmd.exe ";
p.Close();
//解压Rar文件
string path=Server.MapPath( "..\\skins ")+ "\\ "+filename.Substring(filename.LastIndexOf( "\\ ")).Substring(0,filename.Substring(filename.LastIndexOf( "\\ ")).Length-4 );
string ServerDir=@ "C:\Program Files\WinRAR ";//rar路径
System.Diagnostics.Process Process1=new Process();
Process1.StartInfo.FileName=ServerDir+ "\\Rar.exe ";
Directory.CreateDirectory(path); //创建解压文件夹
Process1.StartInfo.Arguments= " x -inul -y "+path+ " "+path;
Process1.Start();//解压开始
while(!Process1.HasExited)//等待解压的完成
{
}
File.Delete(path+ ".rar ");
[解决办法]
学习
[解决办法]
学习
[解决办法]
mark
[解决办法]
Process1.StartInfo.Arguments= " x -inul -y "+path+ " "+path;
解压命令 我是网上找的,path就是解压文件到路径
我试过,行的
[解决办法]
mark.
[解决办法]
学习