asp.net实现文件解压和压缩
C#解压RAR压缩文件(--转载--测试通过)
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Win32;
using System.Diagnostics; namespace Uni.UniCustoms
{
public class clsWinrar
{
/// <summary>
/// 是否安装了Winrar
/// </summary>
/// <returns></returns>
static public bool Exists()
{
RegistryKey the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
return !string.IsNullOrEmpty(the_Reg.GetValue("").ToString());
} /// <summary>
/// 打包成Rar
/// </summary>
/// <param name="patch"></param>
/// <param name="rarPatch"></param>
/// <param name="rarName"></param>
public void CompressRAR(string patch, string rarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
//the_rar = the_rar.Substring(1, the_rar.Length - 7);建议删除
Directory.CreateDirectory(patch);
//命令参数
//the_Info = " a " + rarName + " " + @"C:Test?70821.txt"; //文件压缩
the_Info = " a " + rarName + " " + patch + " -r"; ;
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//打包文件存放目录
the_StartInfo.WorkingDirectory = rarPatch;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 解压
/// </summary>
/// <param name="unRarPatch"></param>
/// <param name="rarPatch"></param>
/// <param name="rarName"></param>
/// <returns></returns>
public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info; try
{
the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
//the_rar = the_rar.Substring(1, the_rar.Length - 7); if (Directory.Exists(unRarPatch) == false)
{
Directory.CreateDirectory(unRarPatch);
}
the_Info = "x " + rarName + " " + unRarPatch + " -y"; ProcessStartInfo the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径 Process the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
return unRarPatch;
}
}
} RAR参数:
一、压缩命令
、将temp.txt压缩为temp.rarrar a temp.rar temp.txt
、将当前目录下所有文件压缩到temp.rarrar a temp.rar *.*
、将当前目录下所有文件及其所有子目录压缩到temp.rarrar a temp.rar *.* -r
、将当前目录下所有文件及其所有子目录压缩到temp.rar,并加上密码123rar a temp.rar *.* -r -p123
二、解压命令
、将temp.rar解压到c:\temp目录rar e temp.rar c:\temprar e *.rar c:\temp(支持批量操作)
、将temp.rar解压到c:\temp目录,并且解压后的目录结构和temp.rar中的目录结构一 压缩目录test及其子目录的文件内容
Wzzip test.zip test -r -P
WINRAR A test.rar test -r 删除压缩包中的*.txt文件
Wzzip test.zip *.txt -d
WinRAR d test.rar *.txt 刷新压缩包中的文件,即添加已经存在于压缩包中但更新的文件
Wzzip test.zip test -f
Winrar f test.rar test 更新压缩包中的文件,即添加已经存在于压缩包中但更新的文件以及新文件
Wzzip test.zip test -u
Winrar u test.rar test 移动文件到压缩包,即添加文件到压缩包后再删除被压缩的文件
Wzzip test.zip -r -P -m
Winrar m test.rar test -r 添加全部 *.exe 文件到压缩文件,但排除有 a或b
开头名称的文件
Wzzip test *.exe -xf*.* -xb*.*
WinRAR a test *.exe -xf*.* -xb*.* 加密码进行压缩
Wzzip test.zip test
-s123。注意密码是大小写敏感的。在图形界面下打开带密码的压缩文件,会看到+号标记(附图1)。
WINRAR A test.rar test -p123
-r。注意密码是大小写敏感的。在图形界面下打开带密码的压缩文件,会看到*号标记(附图2)。 按名字排序、以简要方式列表显示压缩包文件
Wzzip test.zip -vbn
Rar l test.rar 锁定压缩包,即防止未来对压缩包的任何修改
无对应命令
Winrar k test.rar 创建360kb大小的分卷压缩包
无对应命令
Winrar a -v360 test 带子目录信息解压缩文件
Wzunzip test -d
Winrar x test -r 不带子目录信息解压缩文件
Wzunzip test
Winrar e test 解压缩文件到指定目录,如果目录不存在,自动创建
Wzunzip test newfolder
Winrar x test newfolder 解压缩文件并确认覆盖文件
Wzunzip test -y
Winrar x test -y 解压缩特定文件
Wzunzip test *.txt
Winrar x test *.txt 解压缩现有文件的更新文件
Wzunzip test -f
Winrar x test -f 解压缩现有文件的更新文件及新文件
Wzunzip test -n
Winrar x test -u 批量解压缩文件
Wzunzip *.zip
WinRAR e *.rar
asp.net实现文件解压和压缩的更多相关文章
- Linux:文件解压与压缩
文件打包与压缩 常见压缩文件格式: |文件后缀名 |说明| |.zip |zip程序打包压缩的文件| |.rar |rar程序压缩的文件| |.7z |7zip程序压缩的文件| |.tar |tar程 ...
- linux .tar.xz 文件解压和压缩
场景:centos7.0下文件格式为xxx.tar.xz,解压和压缩命令: 压缩 tar -Jcf linux-3.10.0-123.13.1.el7.tar.xz(文件名) linux-3.10.0 ...
- zip文件解压或压缩
<span style="font-size:18px;">/** * lsz */ public final class ZipUtil { /** * 解压zip文 ...
- Liunx文件解压与压缩
文件压缩和解压缩 常见压缩格式如下 .zip .gz .bz2 .tar.gz .tar.gz2 .zip压缩 zip 压缩文件名 源文件 压缩文件 zip -r(递归) 压缩文件名 源目录 压缩目录 ...
- c++builder ZIP文件解压与压缩(ZLIB DLL调用)(转载 )
转载:http://blog.csdn.net/goodai007/article/details/7414512 头文件:ZipAndFile.h //----------------------- ...
- Mac上zip,rar,tar文件命令解压和压缩
经常遇到在windowns上的压缩文件,在mac上解压出现问题,特意总结了下在Terminal里常用命令的方式解压和压缩文件 1.zip压缩文件 zip命令的参数很多,可以利用"zip -- ...
- os与操作系统进行交互,sys解释器相关,random随机数,shutil解压和压缩
1.os 与操作系统相关 对文件的处理 对路径的处理 import os#主要用于与操作系统进行交互 掌握: print(os.makedirs('a/b/c'))#创建目录 可用递归创建 print ...
- linux 如何对文件解压或打包压缩
tar命令用与对文件打包压缩或解压,格式: tar [选项] [文件] 打包并压缩文件: tar -czvf 压缩包名 .tar.gz 解压并展开压缩包: tar -xzvf 压缩包名 .tar. ...
- C# 解压RAR压缩文件
此方法适用于C盘windows文件夹中有WinRAR.exe文件 /// 解压文件(不带密码) RAR压缩程序 返回解压出来的文件数量 /// </summary> /// <par ...
随机推荐
- WCF 基础
ServiceModel 配置元素 Binding 配置元素: 客户端Web.config: <?xml version="1.0" encoding="utf-8 ...
- Linux下配置安装PHP环境
参考别人的做法,遇到问题上网查,下面就是安装步骤. 一.安装Apache2.2.221.到官网下载 http://httpd.apache.org/download.cgi 2.解压 t ...
- NGUI Tutorial 3
一. Create a Button 一.(Menu)NGUI -> Create -> Sprite 二.attach box colider to the Sprite , then ...
- 【面试题032】从1到n整数中1出现的次数
[面试题032]从1到n整数中1出现的次数 题目: 输入一个整数n,求从1到n这n个整数的十进制表示中1出现的次数. 例如输入12,从1到12这些整数中包含1的数字有1,10,11和1 ...
- Android 一个Activity保存它自己的实例
一个Activity保存他自己的实例的作用是,在其他Activity中可以方便的调用该Activity里的方法. 我们可以使用一个静态的变量保存当前Activity的实例,并将其标志为private访 ...
- httpclient发送multipart/form-data类型参数和用MultipartRequest接收参数
一.利用HttpClient发送基于Content-Type="multipart/form-data"形式的表单 package com.test.httpclient; imp ...
- [2-sat]HDOJ1824 Let's go home
中问题 题意略 和HDOJ 3062一样 这里 每个队员都有 选 和 不选 两种, 即 上篇所说的$x$和$x’$ 建图:队长(a)留下或者其余两名队员(b.c)同时留下 那么就是$a' \Right ...
- Project Euler 94:Almost equilateral triangles 几乎等边的三角形
Almost equilateral triangles It is easily proved that no equilateral triangle exists with integral l ...
- 欧拉工程第70题:Totient permutation
题目链接 和上面几题差不多的 Euler's Totient function, φ(n) [sometimes called the phi function]:小于等于n的数并且和n是互质的数的个 ...
- 什么是spring?
一.对spring的理解. 1.Spring是实现了工厂模式的工厂类(什么是工厂类?简单的来说就是把需要的接口定义到一个类中,需要的时候不用新建,直接从这个类中调用该接口就可以了), 这个类的名字为B ...