zoukankan      html  css  js  c++  java
  • C# 利用WinRAR (加密)压缩及解压缩 相关文件夹及文件

    本次示例主要实现:
    1.压缩文件夹及其下文件
    2.压缩文件夹下文件
    3.压缩文件夹及其下文件为rar 还是 zip
    4.解压缩
    5.加密压缩及解加密压缩
    -----------
    示例代码如下:
    protected void Button1_Click(object sender, EventArgs e)
        {
            string strtxtPath = "C:\\freezip\\free.txt";
            string strzipPath = "C:\\freezip\\free.zip";
            System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
            Process1.StartInfo.FileName = "Winrar.exe";
            Process1.StartInfo.CreateNoWindow = true;

            //// 1
            ////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
            ////到c:\freezip\free.rar
            //strzipPath = "C:\\freezip\\free";//默认压缩方式为 .rar
            //Process1.StartInfo.Arguments = " a -r " + strzipPath + " " + strtxtPath;

            //// 2
            ////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
            ////到c:\freezip\free.rar
            //strzipPath = "C:\\freezip\\free";//设置压缩方式为 .zip
            //Process1.StartInfo.Arguments = " a -afzip " + strzipPath + " " + strtxtPath;

            //// 3
            ////压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
            ////到c:\freezip\free.zip  直接设定为free.zip
            //Process1.StartInfo.Arguments = " a -r "+strzipPath+" " + strtxtPath ;

            //// 4
            ////搬迁压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
            ////到c:\freezip\free.rar 压缩后 原文件将不存在
            //Process1.StartInfo.Arguments = " m " + strzipPath + " " + strtxtPath;

            //// 5
            ////压缩c:\freezip\下的free.txt(即文件free.txt)
            ////到c:\freezip\free.zip  直接设定为free.zip 只有文件 而没有文件夹
            //Process1.StartInfo.Arguments = " a -ep " + strzipPath + " " + strtxtPath;

            //// 6
            ////解压缩c:\freezip\free.rar
            ////到 c:\freezip\
            //strtxtPath = "c:\\freezip\\";
            //Process1.StartInfo.Arguments = " x " + strzipPath + " " + strtxtPath;

            //// 7
            ////加密压缩c:\freezip\free.txt(即文件夹及其下文件freezip\free.txt)
            ////到c:\freezip\free.zip  密码为123456 注意参数间不要空格
            //Process1.StartInfo.Arguments = " a -p123456 " + strzipPath + " " + strtxtPath;

            //// 8
            ////解压缩加密的c:\freezip\free.rar
            ////到 c:\freezip\   密码为123456 注意参数间不要空格
            //strtxtPath = "c:\\freezip\\";
            //Process1.StartInfo.Arguments = " x -p123456 " + strzipPath + " " + strtxtPath;

           //// 9 
           ////-o+ 覆盖 已经存在的文件
           //// -o- 不覆盖 已经存在的文件
           //strtxtPath = "c:\\freezip\\";
           //Process1.StartInfo.Arguments = " x -o+ " + strzipPath + " " + strtxtPath;

           ////10
           //// 只从指定的zip中
           //// 解压出free1.txt
           //// 到指定路径下
           //// 压缩包中的其他文件 不予解压
           //strtxtPath = "c:\\freezip\\";
           //Process1.StartInfo.Arguments = " x " + strzipPath + " " +" free1.txt" + " " + strtxtPath;

          //// 11
          //// 通过 -y 对所有询问回应为"是" 以便 即便发生错误 也不弹出WINRAR的窗口
          //// -cl 转换文件名为小写字母 
          //strtxtPath = "c:\\freezip\\";
          //Process1.StartInfo.Arguments = " t -y -cl " + strzipPath + " " + " free1.txt";

            Process1.Start();   
            if (Process1.HasExited)
            {
                    int iExitCode = Process1.ExitCode;
                    if (iExitCode == 0)
                    {
                        Response.Write(iExitCode.ToString() + " 正常完成");
                    }
                    else
                    {
                        Response.Write(iExitCode.ToString() + " 有错完成");
                    }
            }
        }

  • 相关阅读:
    iOS屏幕旋转
    iOS使用NSURLSession发送POST请求,后台无法接受到请求过来的参数
    iOS NET Error Code
    Android App在Google App Store中搜不到
    postman中 form-data、x-www-form-urlencoded、raw、binary的区别
    Android的缓存图片不在系统图库中显示的解决办法
    Android的Notification相关设置
    iOS+PHP图片上传
    解决ndk编译lua时遇到 undefined reference to '__srget'的问题
    避免修改Android.mk添加cpp文件路径
  • 原文地址:https://www.cnblogs.com/freeliver54/p/622992.html
Copyright © 2011-2022 走看看