public void RARsave(string rarPatch, string rarFiles,string patch,string rarName)
{
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);
if (!Directory.Exists(patch))
Directory.CreateDirectory(patch);
//命令参数
//the_Info = " a c:\\test.rar a.txt -r"; //文件压缩
the_Info = string.Format(" a -df {0}\\{1} {2} -r", patch, rarName, rarFiles);// " a " + rarName + " " + patch;
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//打包文件存放目录
the_StartInfo.WorkingDirectory = rarPatch;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
}
public string unRAR(string rarPath, string rarName, string unRarPath)
{
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);
if (!Directory.Exists(unRarPath + "\\" + rarName.Substring(0, rarName.LastIndexOf(".")-1)))
Directory.CreateDirectory(unRarPath + "\\" + rarName.Substring(0, rarName.LastIndexOf(".")-1));
the_Info = string.Format("x {0} {1}\\{2} -y", rarName, unRarPath, rarName.Substring(0, rarName.LastIndexOf(".")-1));
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = rarPath;//获取压缩包路径
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
return "";//Server.MapPath(unRarPatch);
}
public string unRAR(string rarPath, string rarName, string unRarPath, string unRarPathName)
{
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);
//if (!Directory.Exists(unRarPath + "\\" + unRarPathName))
// Directory.CreateDirectory(unRarPath + "\\" + unRarPathName);
//the_Info = string.Format("x {0} {1}\\{2} -y", rarName, unRarPath, unRarPathName);
if (!Directory.Exists(unRarPath ))
Directory.CreateDirectory(unRarPath);
the_Info = string.Format("x {0} {1} -y", rarName, unRarPath);
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = rarPath;//获取压缩包路径
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
return "";//Server.MapPath(unRarPatch);
}
RARsave("c:\\emrbs", "1.txt 2.txt", "c:\\test", "test.rar");
unRAR("d:\\","f.rar","d:\\ftest");
分享到:
相关推荐
c# 压缩和解压缩自己写的一个例子,并非用到SharpZipLib来压缩和解压文件,而是自己引写老外的,然后改写了一个,也没用到.NET自带的压缩与解压缩。 比他们都好的压缩!!!!
C# rar 文件压缩 .net 压缩文件 RAR
在C#中利用SharpZipLib进行文件的压缩和解压缩调用C#源码
本程序完全用C#编写,实现了解压缩、压缩单个文件、压缩文件夹功能
C#压缩和解压缩文件的经典源码,分享给大家。非常好的资源,留着备用吧。
c# 调用RAR 进行 加密 压缩、解压实例
C# RAR 压缩文件例子 自己做的练习 开发环境 VS2010
这里描述了如何使用 C#实现文件的压缩和解压缩
c# 调用c++ 的简单实验
这个是对压缩文件的加密和解密操作。支持zip,jar,rar三种格式的压缩加密和解密,很方便使用,欢迎大家下载,交流
C# rar和zip压缩解压缩代码,支持文件夹压缩和目录压缩
C#利用Winrar来压缩和解压缩 C#利用Winrar来压缩和解压缩
基于哈弗曼编码实现高压缩和解压缩的C#源码,压缩效率高,源码呈现给大家,共同学习
c# 利用WinRAR压缩解压缩文件 本例运用c#调用WinRAR进行压缩和解压缩
在VS2005中调用RAR软件进行压缩
使用c# 编写窗体,点击加载视频,点击压缩按钮后,把视频加入队列,进行排队等待压缩,压缩使用的是ffmpeg。
Grearo图片压缩工具 功能介绍【必读】: 1 图片批量压缩(30以内,依个人机器以及被压缩图片大小而定); 2 图片限定宽度,等比例压缩; 3 图片限定高度,等比例压缩; 4 图片限定高度,宽度压缩;...
c#zip压缩与解压c#zip压缩与解压c#zip压缩与解压c#zip压缩与解压c#zip压缩与解压