asp 可否压缩_怎样用ASP压缩文件

本文介绍如何使用WScript.Shell在服务器上创建压缩文件(ZipFile),并提供示例代码,用于指定文件路径和下载链接。重点在于通过CreateZipFile函数实现文件压缩,适用于需要管理文件的场景。

多数的时候我们需要压缩文件,保存到特定的位置,或者你可以使用它实现所有你想要的效果。

我们需要服务器支持WScript.Shell-多数的站长都不会允许这样的。

这里你可以获取下载链接,在下载这个文件之前你可以要么指定相对的路径或者是绝对的路径,然后点击这里下载。

-zipfile.asp

< %

'---------------------------------------------------------

'CreateZipFile: function to create zip file at particular location 创建Zip文件:在特定位置zip文件的功能

'ZipPath - full path for the zip file, including the zip file name. Zip路径--zip文件的完整路径,包括zip文件名

'arrFilesPath - array of the files to be zipped, arr文件路径—被压缩文件的排列组

e.g. Array("C:\*.exe", "C:\foldername\*.*")

注意:这个代码需要在相同位置的ZIP.EXE效果。

正如这个文件

'---------------------------------------------------------

Sub CreateZipFile(ZipPath, arrFilesPath)

Const PKZIP_FILE_NAME="zip.exe"

Dim strCommand, objShell, objFSO

Dim x

首先检查zip.exe文件里面的:

Set objFSO=Server.CreateObject("Scripting.FileSystemObject")

If Not(objFSO.FileExists(Server.MapPath(ZIP_FILE_NAME) )) Then

Set objFSO=Nothing

Err.Raise 20000, "Zip File Creator", "zip utility not found: "&Server.MapPath(ZIP_FILE_NAME)

End If

删除当前的文件:

If objFSO.FileExists(ZipPath) Then

objFSO.DeleteFile(ZipPath)

End If

Set objFSO=Nothing

批量命令:

strCommand=Server.MapPath(ZIP_FILE_NAME)&" -add "&ZipPath&" "

For x=0 To UBound(arrFilesPath)

strCommand=strCommand&arrFilesPath(x)

If x < UBound(arrFilesPath) Then strCommand=strCommand&" "

Next

执行:

Set objShell=Server.CreateObject("WScript.Shell")

objShell.Run strCommand, 0, True 'wait!

完成:

Set objShell=Nothing

End Sub

%>

now u can call your CreateZipFile() function

-checkZipFile.asp

< %

Call checkZipFile()

Sub checkZipFile()

创建zip和给出链接:

Call CreateZipFile(Server.MapPath("Testzip.zip"), Array(Server.MapPath("images")&"\*.*"))

Response.Write("click here download zip")

End Sub

%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值