Welcome to Gaia! ::

Superlative International Programmers

Back to Guilds

programming help, discussion, games, alot more 

Tags: programming, discussion, computer help, linux help, windows help 

Reply Script Programming
Creating zip files using classic ASP

Quick Reply

Enter both words below, separated by a space:

Can't read the text? Click here

Submit

Judge Advocate
Captain

PostPosted: Mon Jan 25, 2010 5:01 pm


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:
--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 Next

'execute:
Set objShell=Server.CreateObject("WScript.Shell")
objShell.Run strCommand, 0, True 'wait!

'done.
Set objShell=Nothing
End Sub
%>


usage sample 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("download zip")
End Sub
%>
 
PostPosted: Tue Jan 26, 2010 12:03 pm


lol i'ma take some credit for this..

king Nexus
Vice Captain

Reply
Script Programming

 
Manage Your Items
Other Stuff
Get GCash
Offers
Get Items
More Items
Where Everyone Hangs Out
Other Community Areas
Virtual Spaces
Fun Stuff
Gaia's Games
Mini-Games
Play with GCash
Play with Platinum