C#?調(diào)用WinRar執(zhí)行rar、zip壓縮的代碼

在研發(fā)過(guò)程中,將內(nèi)容過(guò)程中比較好的一些內(nèi)容做個(gè)收藏,如下內(nèi)容內(nèi)容是關(guān)于 C# 調(diào)用WinRar執(zhí)行rar、zip壓縮的內(nèi)容,應(yīng)該能對(duì)小伙伴有一些好處。

? ? ? ?

? ? ? ? private static bool ExistsRar(out String winRarPath)

? ? ? ? {

? ? ? ? ? ? winRarPath = String.Empty;

? ? ? ? ? ? var registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionApp PathsWinRAR.exe");

? ? ? ? ? ? return !String.IsNullOrEmpty(winRarPath);

? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

壓縮

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? public static void CompressRar(String path, String rarPath, String rarName)

? ? ? ? {

? ? ? ? ? ? try

? ? ? ? ? ? {

? ? ? ? ? ? ? ? String winRarPath = null;

? ? ? ? ? ? ? ? var pathInfo = String.Format("a -afzip -m0 -ep1 "{0}" "{1}"", rarName, path);

? ? ? ? ? ? ? ? #region WinRar 用到的命令注釋

? ? ? ? ? ? ? ? #endregion

? ? ? ? ? ? ? ? var process = new Process

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? StartInfo = new ProcessStartInfo

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? },

? ? ? ? ? ? ? ? };

? ? ? ? ? ? }

? ? ? ? ? ? catch (Exception ex)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? throw ex;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

解壓

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? public static String UnCompressRar(String unRarPath, String rarPath, String rarName)

? ? ? ? {

? ? ? ? ? ? try

? ? ? ? ? ? {

? ? ? ? ? ? ? ? String winRarPath = null;

? ? ? ? ? ? ? ? if (Directory.Exists(unRarPath) == false)

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? Directory.CreateDirectory(unRarPath);

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? var pathInfo = "x " + rarName + " " + unRarPath + " -y";

? ? ? ? ? ? ? ? var process = new Process

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? StartInfo = new ProcessStartInfo

? ? ? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? },

? ? ? ? ? ? ? ? };

? ? ? ? ? ? }

? ? ? ? ? ? catch (Exception ex)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? throw ex;

? ? ? ? ? ? }

? ? ? ? ? ? return unRarPath;

? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ?

? ? ? ? ? ?

? ? ? ? ? ?

? ? ? ? ? ? ? ?

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容