如何实现 ASP自动解压和压缩RAR文件

发布时间:2007年01月24日      浏览次数:1938 次
<%
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'\\
'\\ compressPath(byVal s)
'\\ 压缩文件的路径 | 字符串变体
'\\
'\\ decompressPath(byVal s)
'\\ 解压缩文件的文件夹 | 字符串变体
'\\
'\\ compress
'\\ 在线压缩 | sub
'\\
'\\ decompress
'\\ 在线解压缩 | sub
'\\
'\\ POWER BY MIRACLE (BLUEDESTINY)
'\\
'\\ EMAIL : Bluedestiny[at]126.com
'\\
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'OPTION EXPLICIT
class COMPRESS_DECOMPRESS_FILES
private version, copyright
private oWshShell, oFso
private sCompressPath, sDecompressPath
private sub class_initialize'类初始化
       Set oFso=server.CreateObject("scripting.FileSystemObject")
       Set oWshShell=server.CreateObject("Wscript.Shell")
end Sub
private sub class_terminate
       if isobject(oWshShell) then set oWshShell=nothing
       if isobject(oFso) then set oFso=nothing
end Sub

'=====================================
'压缩文件
'=====================================
public sub compress'压缩文件
       if not oFso.FolderExists(sDecompressPath) then
             response.write "要进行压缩的文件夹不存在!"'判断文件夹是否存在
             response.end
       end if
       oWshShell.run("WinRAR A " + sCompressPath + " " + sDecompressPath & "")'压缩文件
       if Err.number>0 then
             response.write("压缩失败!")
       else
             response.write("压缩 [b]" + sDecompressPath + "[/b] to [b]" + sCompressPath + ".rar[/b] 成功!")
       end if
end Sub

'=====================================
'解压文件
'=====================================
public sub decompress'解压文件
       'validateFile(sCompressPath)
       if oFso.FileExists(sCompressPath) then '判断文件是否存在
             response.write "要解压的文件不存在!"
             response.end
       end if
       if not oFso.FolderExists(sDecompressPath) then'如果解压文件夹不存在,则生成
             oFso.createFolder(sDecompressPath)
       end if
       oWshShell.run("WinRAR X " + sCompressPath + " " + sDecompressPath & "")'解压文件
       if Err.number>0 then
             response.write("解压失败!")
       else
             response.write("解压 [b]" + sCompressPath + ".rar[/b] to [b]" + sDecompressPath + "[/b] 成功!")
       end if
end sub
public property Let compressPath(byVal s)'定义"压缩文件的名称"的属性
       sCompressPath=server.mappath(s)
end property
public property Let decompressPath(byVal s)'定义"文件夹名称"的属性
       sDecompressPath=server.mappath(s)
end property
End class
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
* {
font-size:10.2pt;
font-family:tahoma;
}
</style>
</HEAD>
<BODY>
<%
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'\\
'\\ 设有压缩文件 compress.rar
'\\ 需压缩文件 decompressFolder 文件夹
'\\
'\\ 将 compress.rar 解压缩至 1 文件夹
'\\ 将 decompressFolder 文件夹 压缩至 2.rar
'\\
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
dim oExample
set oExample=new COMPRESS_DECOMPRESS_FILES
oExample.compressPath="2222" '压缩文件*.rar所生成的文件夹名
oExample.decompresspath="1" '要压缩的文件夹
oExample.compress
oExample.compressPath="2222.rar" '压缩文件的路径此处为D:\导购测评网站\access版(780px)\asp_rar\asp_rar.rar
oExample.decompresspath="2" '解压缩文件的文件夹D:\导购测评网站\access版(780px)\asp_rar\2
oExample.decompress
set oExample=nothing
%>
</BODY>
</HTML>
文章来源:http://bbs.dvbbs.net/dispbbs.asp?boardid=1&id=1137208
免责声明:本站相关技术文章信息部分来自网络,目的主要是传播更多信息,如果您认为本站的某些信息侵犯了您的版权,请与我们联系,我们会即时妥善的处理,谢谢合作!