利用好压在C#程序里实现RAR格式的压缩和解压功能

public static void UnZipFile(string strFromFilePath, string strToFilePath)
{
Process proc = new Process();
try
{
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
string strZipPath = System.Windows.Forms.Application.StartupPath + "\\HaoZip\\HaoZipC.exe";
string dosLine = strZipPath + " e " + strFromFilePath + " -o" + strToFilePath;
proc.StandardInput.WriteLine(dosLine);
proc.StandardInput.WriteLine("exit");
while (!proc.HasExited)
{
proc.WaitForExit(1000);
}
List<string> lstAllIp = new List<string>();
string strInfo = proc.StandardOutput.ReadToEnd();
System.IO.File.Delete(strFromFilePath);
}
catch
{

}
}
public static void ZipFile(string strFromFilePath, string strToFilePath)
{
Process proc = new Process();
try
{
proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
string strZipPath = System.Windows.Forms.Application.StartupPath + "\\HaoZip\\HaoZipC.exe";
string dosLine = strZipPath + " a -tzip " + strToFilePath + " " + strFromFilePath;
proc.StandardInput.WriteLine(dosLine);
proc.StandardInput.WriteLine("exit");
while (!proc.HasExited)
{
proc.WaitForExit(1000);
}
List<string> lstAllIp = new List<string>();
string strInfo = proc.StandardOutput.ReadToEnd();
System.IO.File.Delete(strFromFilePath);
}
catch
{

}
}

上述两个方法的运行要求:1、需要把好压安装后的HaoZip目录拷贝到程序根目录 2、需要添加引用 using System.Diagnostics;

posted @   星星c#  阅读(466)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示