您的位置广东网盟 > 文章资讯 > 软件应用 > 编程开发 > ASP技术 > 文章内容

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

作者:佚名  来源:本站整理  发布时间:2008-9-25 8:53:36

<%

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'\\
'\\ 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>

 

Tags:广东网盟  
  •         用户名: 验证码: 验证码,看不清楚请点击刷新验证码 (注“”为必填内容。)


    文章评论: [ 查看全部 ] 网友评论
    关于网盟 | 网站帮助 | 广告合作 | 下载声明 | 友情连接 | 联系方式

    Copyright © 2003-2008 Gdwg.Net. All Rights Reserved .
    中国广东网管联盟设计维护.网站备案:粤ICP备08020875号