在研發(fā)過程中,將內(nèi)容過程中比較好的一些內(nèi)容做個收藏旱眯,如下內(nèi)容內(nèi)容是關(guān)于 C# 調(diào)用WinRar執(zhí)行rar晨川、zip壓縮的內(nèi)容证九,應(yīng)該能對小伙伴有一些好處删豺。
? ? ? ?
? ? ? ? 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;
? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ?
? ? ? ? ? ?
? ? ? ? ? ?
? ? ? ? ? ? ? ?