转自:http://www.jb51.net/article/68916.htm
本次示例主要实现: 1.压缩文件夹及其下文件 2.压缩文件夹下文件 3.压缩文件夹及其下文件为rar 还是 zip 4.解压缩 5.加密压缩及解加密压缩
示例代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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; Process1.Start(); if (Process1.HasExited) { Response.Write("完成"); } }
re: C# (加密)压缩及解压缩 相关文件夹及文件 更多WinRAR命令(引自WinRAR帮助文档) a 添加文件到压缩文件 c 添加压缩文件注释 d 从压缩文件删除文件 e 从压缩文件解压压缩,忽略路径 f 刷新压缩文件中的文件 i 在压缩文件中查找字符串 k 锁定压缩文件 m 移动文件和文件夹到压缩文件 r 修复受损的压缩文件 rc 重建丢失的卷 rn 重命名压缩文件 rr[N] 添加数据恢复记录 rv[N] 创建恢复卷 s[name] 转换压缩文件成为自解压文件类型 s- 删除自解压模块 t 测试压缩文件 u 从压缩文件中更新文件 x 以完整路径名称从压缩文件解压压缩 回复 更多评论
re: C# (加密)压缩及解压缩 相关文件夹及文件 更多WinRAR字母开头(引自WinRAR帮助文档) -ac 在压缩或解压后清除存档属性 -ad 附加压缩文件名到目标路径中 -af<类型> 指定压缩文件格式 -ag[格式] 以当前日期生成压缩文件名 -ao 添加有存档属性设置的 -ap 设置内部压缩文件路径 -as 同步化压缩文件内容 -av 应用用户身份校验信息 -av- 禁用添加用户身份校验信息 -cfg- 忽略默认配置和环境变量 -cl 将文件名转换成为小写 -cu 将文件名转换成为大写 -df 压缩后删除压缩文件 -dh 打开共享的文件 -ds 不排序压缩的文件 -ed 不添加空文件夹 -en 不添加“压缩文件结束”块 -ep 从名称中排除路径 -ep1 从名称中排除主文件夹 -ep2 扩大成完整路径 -ep3 扩展包含盘符的完整路径 -e[+]<属性> 设置文件排除和包含属性 -f 刷新文件 -hp[密码] 加密文件数据和头 -ibck 在后台运行 WinRAR -ieml 使用E-mail发送压缩文件 -iicon<名称> 指定自解压图标 -iimg<名称> 指定自解压图片 -ilog[名称] 记录错误到文件中 -inul 关闭错误信息 -ioff 关闭 PC 电源 -k 锁定压缩文件 -kb 保留坏掉的解压文件 -m 设置压缩方式 -mc<参数> 设置高级压缩参数 -md 选择字典大小 -ms 指定文件存储 -n<文件> 仅包含指定的文件 -n@<列表文件> 使用指定的列表文件包含文件 -os 保存 NTFS 数据流 -oc 设置 NTFS “压缩”属性 -ow 处理文件用户身份校验信息 -o+ 覆盖已存在的文件 -o- 不要覆盖已存在的文件 -p[密码] 设置密码 -r 返回子文件夹 -r0 只返回与通配符匹配的子文件夹 -ri 设置优先级和休眠时间 -rr[N] 添加数据恢复记录 -rv[N] 创建恢复卷 -s 创建固实压缩文件 -s 以文件数量创建固实组 -se 以文件扩展名创建固实组 -sfx[名称] 创建自解压文件 -sv 创建互不依赖的固实压缩文件 -sv- 创建互相依赖的固实压缩文件 -s- 禁用固实算法 -t 压缩后测试文件 -ta<日期> 只处理指定日期之后修改的文件 -tb<日期> 只处理指定日期之前修改的文件 -tk 保持原有压缩文件时间 -tl 以最新的文件设置压缩文件时间 -tn<时间> 处理较新于指定时间的文件 -to<时间> 处理较旧于指定时间的文件 -ts<m,c,a> 保存或恢复文件时间(修改,创建,访问) -u 更新文件 -v[k|b|f|m|M|g|G] 创建分卷压缩 -vd 创建分卷压缩前清除磁盘内容 -ver 文件版本控制 -vn 使用旧风格的卷命名法则 -vp 每次分卷压缩前暂停 -x<文件> 排除指定的文件 -x@<文件列表> 使用指定的列表文件来排除指定的文件 -y 假设全部的询问回应皆为“是” -z<文件> 从文件读取压缩文件注释 – 停止开关的扫描
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 string strtxtPath = "D://"; string strzipPath = "D://test.rar"; System.Diagnostics.Process Process1 = new System.Diagnostics.Process(); Process1.StartInfo.FileName = "Winrar.exe"; Process1.StartInfo.CreateNoWindow = true; Console.WriteLine(DateTime.Now); Console.WriteLine("开始暴力解密:"); int count = 0; string pwd = string.Empty; for (int a = 0; a < 10; a++) { for (int b = 0; b < 10; b++) { for (int c = 0; c < 10; c++) { for (int d = 0; d < 10; d++) { count++; pwd = "" + a + b + c + d; Console.WriteLine(DateTime.Now); Console.WriteLine("第"+count+"次尝试: pwd = "+pwd); Process1.StartInfo.Arguments = " x -p"+ pwd + " " + strzipPath + " " + strtxtPath; Process1.Start(); System.Threading.Thread.Sleep(3 * 1000); if (Process1.HasExited) { Console.WriteLine("解密成功!"); Console.WriteLine("密码为:"+pwd); Console.ReadLine(); } else { KillProcess("WinRAR"); Console.WriteLine(); } } } } } Console.ReadLine(); } private static void KillProcess(string processName) { Process[] myproc = Process.GetProcesses(); foreach (Process item in myproc) { if (item.ProcessName == processName) { item.Kill(); } } }