2 回答

TA貢獻1951條經(jīng)驗 獲得超3個贊
/// <summary>
/// 壓縮文件夾
/// </summary>
/// <param name="DirectoryName"></param>
/// <param name="ZipFileName"></param>
public static void Zip_Directory(string DirectoryName, string ZipFileName, string SavePath)
{
//壓縮
String myRar;
RegistryKey myReg;
Object myObj;
String myInfo;
ProcessStartInfo myStartInfo;
Process myProcess;
try
{
myReg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRAR.exe\Shell\Open\Command");
myObj = myReg.GetValue("");
myRar = myObj.ToString();
myReg.Close();
myRar = myRar.Substring(1, myRar.Length - 7);
//rar命令參數(shù)
myInfo = "a -r -ep1 " + SavePath + "\\" + ZipFileName + " " + DirectoryName;//a-壓縮 -r -ep1文件夾內(nèi)的全部文件和文件夾加入到壓縮文件 壓縮文件保存地址 要壓縮的目錄
myStartInfo = new ProcessStartInfo();
myStartInfo.FileName = myRar;
myStartInfo.Arguments = myInfo;
myStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myStartInfo.WorkingDirectory = DirectoryName;//獲取或設(shè)置要啟動的進程的初始目錄。
myProcess = new Process();
myProcess.StartInfo = myStartInfo;
myProcess.Start();
}
catch { }
}
調(diào)用WinRar進行壓縮
需要引用的命名空間
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Diagnostics;
- 2 回答
- 0 關(guān)注
- 411 瀏覽
添加回答
舉報