Solved

Zipping multiple files to a single zip file

Posted on 2006-07-14
11
313 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
Comment Utility
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
Comment Utility
0
 
LVL 31

Expert Comment

by:alorentz
Comment Utility
0
 
LVL 1

Author Comment

by:Mark Skrodzki
Comment Utility
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
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 31

Expert Comment

by:alorentz
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
My post suggested the same thing ...
0
 
LVL 1

Author Comment

by:Mark Skrodzki
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now