现在的位置: 首页 > 综合 > 正文

rar实现asp的在线压缩与解压缩

2013年03月08日 ⁄ 综合 ⁄ 共 2587字 ⁄ 字号 评论关闭
前提:
需要wscript支持
你将cmd.exe和winrar文件夹中rar.exe都放到同一个文件夹里
而且这个文件夹取名叫"dos",要不然你自己修改代码文件也成;
(主要是方便,我自己也很懒的,呵呵)
文件保存为同名的文件哦

自解压代码文件
unrar.asp

<%
dim afterunzip,PEDM,Mlpath,Shell,rarcomm,RetCode,cmd,comm,fso 

unfilepath=Request.ServerVariables("PATH_INFO")
<|>response.write Mlpath
<|>response.end

<|>存放RAR.EXE和CMD.EXE的路径 
Mlpath=Replace(Server.mappath(unfilepath),"unrar.asp","")

<|>解压文件后所放的路径
afterunzip=Server.mappath("dos")&"\" 
<|>afterunzip=Mlpath

<|>要解压的RAR文件
PEDM=Server.mappath("aaa.rar")

Set Shell = Server.CreateObject("WScript.Shell") 
<|>x从档案文件中全路径释放文件
<|>t压缩后测试文件
<|>o不覆盖已经存在的文件
<|>p设置口令
rarcomm= Mlpath&"cmd.exe /c "&Mlpath&"rar.exe x -t -o+ -p- " 
cmd=rarcomm&PEDM&" "&afterunzip
RetCode = Shell.Run(cmd,1, True) 
%>

<|><|><|><|><|><|><|><|><|><|><|><|>压缩文件代码
rar.asp

<%
dim ylj,ywj,Mlpath,Shell,rarcomm,RetCode,cmd,comm,fso 

unfilepath=Request.ServerVariables("PATH_INFO")
<|>response.write Mlpath
<|>response.end

<|>存放RAR.EXE和CMD.EXE的路径 
Mlpath=Replace(Server.mappath(unfilepath),"rar.asp","")

<|>压缩文件后所放的路径
afterzip=Server.mappath("dos")&"\" 
<|>ylj=Mlpath

<|>要压缩的RAR文件
needzip=Server.mappath("aaaw.rar")

Set Shell = Server.CreateObject("WScript.Shell") 
<|>x从档案文件中全路径释放文件
<|>t压缩后测试文件
<|>o不覆盖已经存在的文件
<|>p设置口令
rarcomm= Mlpath&"cmd.exe /c "&Mlpath&"rar.exe a -o+ " 
cmd=rarcomm&needzip&" "&afterzip
<|>Response.write cmd
<|>Response.end
RetCode = Shell.Run(cmd,1, True) 
%>

要改成winzip的自己改吧,提供命令行参考:

WinRAR<命令>-<开关><压缩包><文件...><解压缩路径> 

压缩与解压缩操作举例 

下面我们通过例子,对比一下Winzip和Winrar的基本压缩与解压缩操作命令。假设压缩包文件名为test.zip和test.rar。 

任务描述
Winzip     Winrar

压缩目录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

抱歉!评论已关闭.