| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Requirements:
1. Server supporting WScript.Shell - most hosts won't allow this. 2. Command line zip utility called PKZIP25 - can be downloaded from here: http://www.amitbb.co.il/Downloads/temp/PKZIP25.zip Source code: Code:
--ZipFiles.asp
<%
'---------------------------------------------------------
'CreateZipFile: creating zip file in the given path.
'strZipPath - full path for the zip file, including the zip file name.
'arrFilesPath - array of the files to be zipped, e.g. Array("C:\*.exe", "C:\test\*.*")
'NOTE: this code requires PKZIP25.EXE utility in the same location
' as this file.
'---------------------------------------------------------
Sub CreateZipFile(strZipPath, arrFilesPath)
Const PKZIP_FILE_NAME="pkzip25.exe"
Dim strCommand, objShell, objFSO
Dim x
'first verify pkzip exists:
Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
If Not(objFSO.FileExists( Server.MapPath(PKZIP_FILE_NAME) )) Then
Set objFSO=Nothing
Err.Raise 20000, "Zip File Creator", "zip utility not found: "&Server.MapPath(PKZIP_FILE_NAME)
End If
'delete current file, if exists:
If objFSO.FileExists(strZipPath) Then
objFSO.DeleteFile(strZipPath)
End If
Set objFSO=Nothing
'build batch command:
strCommand=Server.MapPath(PKZIP_FILE_NAME)&" -add "&strZipPath&" "
For x=0 To UBound(arrFilesPath)
strCommand=strCommand&arrFilesPath(x)
If x<UBound(arrFilesPath) Then strCommand=strCommand&" "
Next
'execute:
Set objShell=Server.CreateObject("WScript.Shell")
objShell.Run strCommand, 0, True 'wait!
'done.
Set objShell=Nothing
End Sub
%>
usage sample code: Code:
--ZipTest.asp
<% Option Explicit %>
<!-- #include file="ZipFiles.asp" -->
<%
Call TestZipFile()
Sub TestZipFile()
'create zip and give link:
Call CreateZipFile(Server.MapPath("myzip.zip"), Array(Server.MapPath("images")&"\*.*"))
Response.Write("<a href=""myzip.zip"">download zip</a>")
End Sub
%>
Last edited by Shadow Wizard : April 23rd, 2006 at 01:49 AM. |
|
#2
|
||||
|
||||
|
Excellent!
Nice job Shadow, as always ![]()
__________________
Look! Its a ShemZilla ![]() ![]()
|
|
#3
|
||||
|
||||
|
Creating zip files using classic ASP
Shadow,
As the link to download pkzip25.exe no longer works, do you have another link where i can get it from. cheers
__________________
Hope this advise helps. ![]() If so please show your appreciation by adding reputation points (click gauge image on top right of this post and score).
|
|
#4
|
||||
|
||||
|
sorry, I had to remove it from there.
I'll see if I can put it back, can't find link to this version of the file. |
|
#5
|
||||
|
||||
|
ok, I have put it back and changed the link. let me know if there are any
further problems. ![]() |
|
#6
|
|||
|
|||
|
i have implemented this and it works great except for large numbers of files...I have more than 1000 files I need to zip....does pkzip have a limit?
|
|
#7
|
||||
|
||||
|
as far as I know, no limit. what exactly is the problem? you get error?
|
|
#8
|
|||
|
|||
|
no error, just that the code doesn't produce a file. it gets to the part where it deletes an existing zip file that had the same name but then doesn't make one...can't figure out why...it does build a perfect string and all...i've printed that out and looks fine but doesn't go through with making file. i am wondering if wscript.shell has a limit to what it can read in
|
|
#9
|
||||
|
||||
|
sorry, can't see any way to solve this issue.
you can zip only part of the files each time as work around. |
|
#10
|
|||
|
|||
|
I've tried your code and it works great for zipping all the files in a given folder, however, it doesn't include any subfolders in the zip.
I looked through the code and can see how it loops through each file. Is there some way to modify the code so it could include subfolders of a main folder I want to zip? Thanks |
|
#11
|
||||
|
||||
|
Quote:
Code:
strCommand=Server.MapPath(PKZIP_FILE_NAME)&" -add "&strZipPath&" " to be this: Code:
strCommand=Server.MapPath(PKZIP_FILE_NAME)&" -add -rec "&strZipPath&" " |
|
#12
|