Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 27th, 2005, 07:29 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
Post Creating zip files using classic ASP

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
%>
Attached Files
File Type: txt ZipFiles.asp.txt (1.3 KB, 988 views)
File Type: txt ZipTest.asp.txt (296 Bytes, 884 views)

Last edited by Shadow Wizard : April 23rd, 2006 at 01:49 AM.

Reply With Quote
  #2  
Old June 27th, 2005, 07:32 AM
nofriends's Avatar
nofriends nofriends is offline
Senior Water Wizard
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Aug 2004
Location: Cape Town, RSA
Posts: 10,186 nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)nofriends User rank is Brigadier General (60000 - 70000 Reputation Level)  Folding Points: 101990 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101990 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101990 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101990 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101990 Folding Title: Super Ultimate Folder - Level 1Folding Points: 101990 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 2 Weeks 2 Days 7 h 36 m 24 sec
Reputation Power: 699
Excellent!
Nice job Shadow, as always
__________________
Look! Its a ShemZilla



Reply With Quote
  #3  
Old April 21st, 2006, 05:42 AM
markoc's Avatar
markoc markoc is offline
Contributing User
ASP Free Regular (2000 - 2499 posts)
 
Join Date: Nov 2003
Location: UK
Posts: 2,151 markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 18 h 10 m 15 sec
Reputation Power: 201
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).

Reply With Quote
  #4  
Old April 21st, 2006, 03:39 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
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.

Reply With Quote
  #5  
Old April 23rd, 2006, 01:50 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
ok, I have put it back and changed the link. let me know if there are any
further problems.

Reply With Quote
  #6  
Old June 30th, 2006, 02:29 PM
coryjohnson coryjohnson is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 2 coryjohnson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 47 sec
Reputation Power: 0
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?

Reply With Quote
  #7  
Old July 1st, 2006, 10:53 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
as far as I know, no limit. what exactly is the problem? you get error?

Reply With Quote
  #8  
Old July 3rd, 2006, 02:02 PM
coryjohnson coryjohnson is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2006
Posts: 2 coryjohnson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 47 sec
Reputation Power: 0
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

Reply With Quote
  #9  
Old July 3rd, 2006, 03:10 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
sorry, can't see any way to solve this issue.
you can zip only part of the files each time as work around.

Reply With Quote
  #10  
Old September 15th, 2008, 08:44 AM
finittz finittz is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 13 finittz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 14 m 12 sec
Reputation Power: 0
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

Reply With Quote
  #11  
Old September 15th, 2008, 09:04 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
ASP Free God 45th Plane (27000 - 27499 posts)
 
Join Date: Sep 2004
Location: Israel
Posts: 27,270 Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1Folding Points: 356912 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 6 Days 12 h 28 m 35 sec
Reputation Power: 1791
Quote:
Originally Posted by finittz
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
try changing this line:
Code:
strCommand=Server.MapPath(PKZIP_FILE_NAME)&" -add "&strZipPath&" "

to be this:
Code:
strCommand=Server.MapPath(PKZIP_FILE_NAME)&" -add -rec "&strZipPath&" "

Reply With Quote
  #12  
Old September 15th, 2008, 09:31 AM