asp实现在线压缩和解压缩

本文介绍了一个使用VBScript编写的简单类模块,该模块能够进行文件压缩和解压缩操作。通过调用WinRAR命令行工具,此脚本可以轻松地将指定文件夹压缩为RAR文件或将RAR文件解压到指定目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

附带实例

<%
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
\
'
\1.c:windows\system32\cmd.exe
'
\拷贝把本文件所在的路径
'
\
'
\2.把c:program\winrar\rar.exe
'
\拷贝把本文件所在的路径并改名为WinRAR.exe
'
\
'
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
\
'
\compressPath(byVals)
'
\压缩文件的路径|字符串变体
'
\
'
\decompressPath(byVals)
'
\解压缩文件的文件夹|字符串变体
'
\
'
\compress
'
\在线压缩
'
\
'
\decompress
'
\在线解压缩
'
\
'
\POWERBYMIRACLE(BLUEDESTINY)
'
\
'
\EMAIL:Bluedestiny[at]126.com
'
\
'
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

OPTIONEXPLICIT

classCOMPRESS_DECOMPRESS_FILES

privateversion,copyright
privateoWshShell,oFso
privatesCompressPath,sDecompressPath

privatesubclass_initialize
version
="COMPRESS_DECOMPRESS_FILESBUILDER20051015"
copyright
="POWERBYMIRACLE(BLUEDESTINY)"
SetoFso=server.CreateObject("scripting.FileSystemObject")
SetoWshShell=server.CreateObject("Wscript.Shell")
writeLn(version
+"<br>"+copyright)
endSub
privatesubclass_terminate
ifisobject(oWshShell)thensetoWshShell=nothing
ifisobject(oFso)thensetoFso=nothing
endSub
privatefunctionphysicalPath(byVals)
physicalPath
=server.mappath(s)
endFunction
privatesubvalidateFile(byVals)
ifoFso.FileExists(s)thenexitsub
ifoFso.FolderExists(s)thenexitsub
callErr
"file(folder)notexists!"
endSub
privatesubcreateFolder(byVals)
ifoFso.FolderExists(s)thenexitSub
oFso.createFolder(s)
endSub
privatesubwriteLn(byVals)
response.write
"<p>"+s+"</p>"+vbCrlf
endSub
privatesubcallErr(byVals)
writeLn
"<p><b>ERROR:</b></p>"+s
response.End
endsub
privatesubcallSucc(byVals)
writeLn
"<p><b>SUCCESS:</b></p>"+s
endSub

publicsubcompress
validateFile(sCompressPath)
oWshShell.run(
"WinRARA"+sCompressPath+""+sDecompressPath&"")
ifErr.number>0thencallErr("compresslost!")
callSucc(
"compress<b>"+sDecompressPath+"</b>to<b>"+sCompressPath+".rar</b>successfully!")
endSub
publicsubdecompress
validateFile(sCompressPath)
createFolder(sDecompressPath)
oWshShell.run(
"WinRARX"+sCompressPath+""+sDecompressPath&"")
ifErr.number>0thencallErr("decompresslost!")
callSucc(
"decompress<b>"+sCompressPath+".rar</b>to<b>"+sDecompressPath+"</b>successfully!")
endsub

publicpropertyLetcompressPath(byVals)
sCompressPath
=physicalPath(s)
endproperty
publicpropertyLetdecompressPath(byVals)
sDecompressPath
=physicalPath(s)
endproperty

Endclass
%
>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
<TITLE>NewDocument</TITLE>
<METANAME="Generator"CONTENT="EditPlus">
<METANAME="Author"CONTENT="">
<METANAME="Keywords"CONTENT="">
<METANAME="Description"CONTENT="">
<style>
*{
font
-size:10.2pt;
font
-family:tahoma;
}
</style>
</HEAD>

<BODY>
<%
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'
\
'
\设有压缩文件compress.rar
'
\需压缩文件decompressFolder文件夹
'
\
'
\将compress.rar解压缩至1文件夹
'
\将decompressFolder文件夹压缩至2.rar
'
\
'
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

dimoExample

setoExample=newCOMPRESS_DECOMPRESS_FILES
oExample.compressPath
="decompressFolder"
oExample.decompresspath
="1"
oExample.compress

oExample.compressPath
="compress.rar"
oExample.decompresspath
="2"
oExample.decompress

setoExample=nothing
%
>
</BODY>
</HTML>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值