Solved

Zipping multiple files to a single zip file

Posted on 2006-07-14
11
319 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: 17110242
0
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!

 
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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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/…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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