Solved

Zipping multiple files to a single zip file

Posted on 2006-07-14
11
318 Views
Last Modified: 2010-07-27
I have a folder on the server that contains numerous .tif files all with the same .tif extension. The following code works great but I believe it was only designed for a few files of different extensions. I know I can add more Server.MapPath lines but the amount of files in the folder on the server will always be changing so this will not work. What I'm looking for is some sort of logic to look through all of the files in the folder and zip all of them into the single .zip file specified.

Any ideas on this???

Mark
0
Comment
Question by:Mark Skrodzki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
11 Comments
 
LVL 1

Author Comment

by:Mark Skrodzki
ID: 17110112
Sorry, I had forgotten to add the code to my question...




<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>


<%
 Dim strResult, theFiles
 theFiles = Server.mappath("/docimages/images/00028E0E.tif") & "*" & _
                    Server.mappath("/docimages/images/00028319.tif")
 set javaObject = GetObject("java:ZipFunctions")
 strResult = javaObject.ZipFile(theFiles, _
                    Server.mappath("/docimages/images.zip"))
                              
 'Display a link to the newly created GZip file
 Dim strLink
 strLink = Replace(Replace(strResult, "Created " & _
                 Server.MapPath("/"), ""), "\", "/")
 strLink = Left(strLink, Len(strLink) - 1)
 'Response.Write "To download file, click on link below"
 'Response.Write "<A HREF=""" & strLink & """>"
 'Response.Write strLink & "</A>"
                               
 'response.write strResult
 set javaObject = nothing
%>





<body>
<p>To download file, click on link below.</p>
<p>&nbsp;</p>
<%
 Response.Write "<A HREF=""" & strLink & """>"
 Response.Write strLink & "</A>"
 %>
</body>
</html>
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17110237
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17110242
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Author Comment

by:Mark Skrodzki
ID: 17111973
THanks for the post!

Here is what I have so far....




<%

Dim objFSO
      Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFolder
Dim strRootFolder
      strRootFolder = "\\granite\inetpub\wwwroot\thelenintranet\docimages\images\"

Set objFolder = objFSO.GetFolder(strRootFolder)

Dim objFile

For Each objFile in objFolder.Files
          'Response.Write objFile.Name & " (" & objFile.Size & " bytes)<BR>"
            'Response.Write objFile.Name & " (" & objFile & " )<BR>"
      If LCase(Right(objFile.Name, 4)) = ".mp3" then
            Response.Write "<B>MP3 File!</B><P>"
          End if

      
      Next
      
%>


<%
 Dim strResult, theFiles
 theFiles = Server.mappath("/docimages/images/00028E0E.tif") & "*"
 set javaObject = GetObject("java:ZipFunctions")
 strResult = javaObject.ZipFile(theFiles, _
                    Server.mappath("/docimages/images2.zip"))
                              
 'Display a link to the newly created Zip file
 Dim strLink
 strLink = Replace(Replace(strResult, "Created " & _
                 Server.MapPath("/"), ""), "\", "/")
 strLink = Left(strLink, Len(strLink) - 1)
 'Response.Write "To download file, click on link below"
 'Response.Write "<A HREF=""" & strLink & """>"
 'Response.Write strLink & "</A>"
                               
 'response.write strResult
 set javaObject = nothing

%>


The problem I am having is, how do I get the correct path to be used inplace of.....Server.mappath("/docimages/images/00028E0E.tif"). THis is where the java script will look for the path/filenames. I have tried numerous syntax's with no luck. Not very good at this stuff!!
ALso, the path were the zip file to be stored needs to be on a file share that is not in the web root folder. Any help on that??

Thanks,
Mark
0
 
LVL 14

Expert Comment

by:dfu23
ID: 17112191
Dim theFiles, javaObject, strResult

' Loop through the files and concatonate a list together
For Each objFile in objFolder.Files
  theFiles = theFiles & strRootFolder & objFile.Name & "*"
Next

' Create the ZIP
Set javaObject = GetObject("java:ZipFunctions")
strResult = javaObject.ZipFile(theFiles, Server.mappath("/docimages/images2.zip"))
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17112225
objfile should contain the full path...


For Each objFile in objFolder.Files
       Response.Write objFile & "<BR>"
Next
0
 
LVL 1

Author Comment

by:Mark Skrodzki
ID: 17132464
Thanks for all of the help so far!!!

Here is the code I have so far. The output I get on the screen is not correct, so the zip function isn't working. This is what I get...
   
"C:\inetpub\wwwroot\thelenintranet\docimages\images\test.txt*"

What I should get is this...
   
"C:\inetpub\wwwroot\thelenintranet\docimages\images\test.txt*C:\inetpub\wwwroot\thelenintranet\docimages\images\test2.txt*C:\inetpub\wwwroot\thelenintranet\docimages\images\test3.txt*....." and so on until the entire file is read. The ZIP function needs the entire file list to be in one line. My current code, puts each filepath/filename into seperate lines. I believe this is causing the problem with the zip function. When the page is run, I get a "Couldn't Compress" error line.

Any ideas???


*************************************************************
<%

Dim objFSO
      Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFolder
Dim strRootFolder
      strRootFolder = "C:\Inetpub\wwwroot\ThelenIntranet\docimages\images\"

Set objFolder = objFSO.GetFolder(strRootFolder)

Dim objFile, theFiles, javaObject


For Each objFile in objFolder.Files
          'Response.Write objFile.Name & " (" & objFile.Size & " bytes)<BR>"
            'Response.Write objFile.Name & " (" & objFile & " )<BR>"
            'Response.Write objFile & "<BR>"
            
            theFiles = strRootFolder & objFile.Name & "*"
            
      
      Next
Response.Write theFiles & "<BR>"      
Dim strResult
      
 set javaObject = GetObject("java:ZipFunctions")
 strResult = javaObject.ZipFile(theFiles,Server.mappath("/docimages/images2/images2.zip"))
                              
 'Display a link to the newly created GZip file
 'Dim strLink
 'strLink = Replace(Replace(strResult, "Created " & Server.MapPath("/"), ""), "\", "/")
 'strLink = Left(strLink, Len(strLink) - 1)
 'Response.Write "To download file, click on link below"
 'Response.Write "<A HREF=""" & strLink & """>"
 'Response.Write strLink & "</A>"
                               
 response.write strResult
 set javaObject = nothing      
      
      
%>

*************************************************************
0
 
LVL 31

Accepted Solution

by:
alorentz earned 500 total points
ID: 17133709
For Each objFile in objFolder.Files
         'Response.Write objFile.Name & " (" & objFile.Size & " bytes)<BR>"
          'Response.Write objFile.Name & " (" & objFile & " )<BR>"
          'Response.Write objFile & "<BR>"
         
          theFiles = theFiles & strRootFolder & objFile.Name & "*" '<----------NEED TO CONCATENATE theFiles  VARIABLE
         
     
     Next
0
 
LVL 14

Expert Comment

by:dfu23
ID: 17316706
My post suggested the same thing ...
0
 
LVL 1

Author Comment

by:Mark Skrodzki
ID: 17317023
Sorry for the length of time it has taken to complete this issue. Much has been going on here taking up most of my time, not being able to finish this project. I will award the points to Alorentz. Thanks for the help

Mark
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP server side get value 15 50
Retreiving SOAP FAULT messages using classical ASP 14 46
PHP $_POST vs asp request 4 57
Save data in two Database, Asp 2 69
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question