Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Zipping multiple files to a single zip file

Posted on 2006-07-14
11
Medium Priority
?
321 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

927 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