Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Zipping multiple files to a single zip file

Posted on 2006-07-14
11
Medium Priority
?
320 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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 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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

670 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