c#调用压缩程序

zhongxingjun 2008-07-10 03:15:58
我想实现鼠标选定几个文件,然后点击一个按钮,自动调用ZIP,或是rar压缩程序,把几个文件压缩成一个文件
...全文
49 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wufan110 2008-07-10
  • 打赏
  • 举报
回复
http://www.soft000.com/down/backFile1.rar
就是用命令.这个就是调用WINRAR做的.
liangqingxing 2008-07-10
  • 打赏
  • 举报
回复
/// <summary>
/// 解压文件类型
/// </summary>
public enum UnCompressType { RAR, ZIP };

/// <summary>
/// 解压 RAR OR ZIP 类型的文件
/// 创 建 人:梁庆星
/// 创建时间:20080429
/// 修 改 人:
/// 修改时间:
/// </summary>
/// <param name="strInputFilePath">待解压的文件路径 例:E:\dir\temp.rar</param>
/// <param name="strOutPath">解压文件后的目标路径 例:E:\outdir\</param>
/// <param name="strType">待解压的文件类型,选则是 "RAE" OR "ZIP" </param>
public void UnCompress(string strInputFilePath, string strOutPath, UnCompressType Type)
{
try
{
Process myProcess = new Process();

myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;
myProcess.StartInfo.CreateNoWindow = true;

if (!Directory.Exists(strOutPath))
Directory.CreateDirectory(strOutPath);

String inputText = String.Empty;
if (Type == UnCompressType.RAR)
{
inputText = "unrar.exe e -o+ " + strInputFilePath + " " + strOutPath;
}
else if (Type == UnCompressType.ZIP)
{
inputText = "unzip.exe -o " + strInputFilePath + " -d " + strOutPath;

}

myProcess.StartInfo.Arguments = "/c " + inputText;

myProcess.Start();
myProcess.WaitForExit();
myProcess.Close();
myProcess.Dispose();
}
catch (Exception exc)
{
LogProxy.STWrite("解压文件时出错,错误原因是:" + exc.Message.ToString());
}
}

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧