Solved

Compress a file to .zip?

Posted on 2002-03-07
12
574 Views
Last Modified: 2008-02-01
How do I compress a file to .zip in a vb-project.
Is there a way to do this for free. I have searched the web and found a couple that costed money.
0
Comment
Question by:ajohans
12 Comments
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6846740
Hi!

Here's a file for you over the net:

Download...
http://www.vbdiamond.com/Sources/DownloadFile.asp?ID=2139
Description: A powerful and very quick compression program using the 32bit zlib.dll (V1.1.3) compression library originally written by Jean-loup Gailly and Mark Adler (variation of LZ77 Lempel-Ziv 1977 algoritm). The application is implemented through an extensive ArielZip class and a Winzip like client interface. Features * Powerful and very fast - compresses 6000 kb data files to 1500 kb (25%) in 2.1 seconds! * Multiple disk spanning with automatic sensing of disk capacity * User friendly floppy disk change dialogue showing contents of disk to be overwritten * Single and multiple file extraction * Extracted icons included in archive as bitmaps * 9 compression levels * Add folders and subfolders through recursive scanning of FSO objects * Add files  
...

Download...
http://www.gzip.org/zlib.zip
Description: ZLIB is a compression library compatible with the gzip format

That's it!

glass cookie : )
0
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 6846742
0
 
LVL 3

Expert Comment

by:tonydspaniard
ID: 6846753
Hi ajohans,
Check the URL posted above, you´ll find a very useful project made by a pal programmer that will teach you the good way of using the FREE zlib.dll zipping library.

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=14087&lngWId=1 


Hope this works
0
 

Author Comment

by:ajohans
ID: 6846771
Does this project compress the files in .zip so that somebody can unpack it in winzip later?
0
 

Author Comment

by:ajohans
ID: 6846799
Does this project compress the files in .zip so that somebody can unpack it in winzip later?
0
 

Author Comment

by:ajohans
ID: 6846837
Does this project compress the files in .zip so that somebody can unpack it in winzip later?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:tonydspaniard
ID: 6846866
ajohans:
This guy did wrote a custom headers to his zipped documents. I thought you wanted to create the same type of applications. For what you want, may be you can do it with the following code

Function winZipit(ByVal source As String, ByVal target As String, ByVal zip As Boolean)
    zipIT = App.Path & "winzip32 -a"
    unzipIT = App.Path & "winzip32 -e "


    If zip = True Then
        Shell (zipIT & target & source)
    Else: Shell (unzipIT & target & source)
    End If
End Function
0
 
LVL 3

Expert Comment

by:tonydspaniard
ID: 6846868
sorry, i forgot to tell you, the code i did submitted is to work with Winzip program.....
0
 
LVL 3

Expert Comment

by:tonydspaniard
ID: 6846873
to work with Winzip to zip unzip:


Adding files:
The command format is:
winzip[32].exe [-min] action [options] filename[.zip] files
where:
-min specifies that WinZip should run minimized. If -min is specified,
it must be the first command line parameter.
action
-a For add, -f for freshen, -u for update, and -m for move. These
actions correspond To the actions described In the section titled
"Adding files To an Archive" in the online manual.
options
-r and -p correspond To the "Recurse Directories" and "Save Extra
Directory Info" checkboxes in the Add and Drop dialog boxes. -ex, -en,
-ef, -es, and -e0 options determine the compression method: eXtra,
Normal, Fast, Super fast, and no compression. The default is "Normal".
-s allows specification of a password. The password can be enclosed
In quotes, For example, -s"Secret Password". Note that passwords are
case-sensitive.
-hs option allows hidden and system files To be included.
filename.zip
Specifies the name of the ZIP involved. Be sure To use the full
filename (including the directory).
files
Is a list of one or more files, or the @ character followed by the
filename containing a list of files To add, one filename per line.
Wildcards (e.g. *.bak) are allowed.
Extracting Files:
The command format is:
winzip[32].exe -e [options] filename[.zip] directory
where:
-e Is required.
options
-o and -j stand For "Overwrite existing files without prompting" and
"Junk pathnames", respectively. Unless -j is specified, directory
information is used.
-s allows specification of a password. The password can be enclosed
In quotes, For example, -s"Secret Password". Note that passwords are
case-sensitive.
filename.zip
Specifies the name of the ZIP involved. Be sure To specify the full
filename (including the directory).
directory
Is the name of the directory to which the files are extracted. If the
directory does Not exist it is created.


Notes:
* VERY IMPORTANT: Always specify complete filenames, including the full
path name and drive letter, For all file IDs.
* To run WinZip in a minimized inactive icon use the "-min" option.
When specified this option must be the first option.
* Only operations involving the built-in zip and unzip are supported.
* Enclose Long filenames on the command line in quotes.
* NO leading or trailing blanks, or blank lines For readability, are
allowed In list ("@") files.
* The action and Each option on the command line must be separated
from the others by at least one space.
* WinZip can be used To compress files With cc:Mail . Change the
compress= line in the [cc:Mail] section of the appropriate WMAIL.INI
files To specify the full path For WinZip followed by "-a %1 @%2".


For example, If WinZip is installed in your c:\winzip directory,
    specify
    compress=c:\winzip\winzip.exe -a %1 @%2

0
 

Author Comment

by:ajohans
ID: 6846992
Thank you for the tip.
I have tried that but I can't get it to work.
I am going to monitor a directory and when a .xml-file appears i am going to create a md5-file from that xml-file and then zip these two files together.
All goes fine until I am going to zip them together.
Sometimes it goes OK for one file but when another zipfile is going to be created the following error appears:


Action: Add (and replace) files Include subfolders: yes Save full path: no
Adding penfile_100_1011344423242_16.md5
Warning: could not open for reading: e:\Project\Anoto\xml-files\penfile_100_1011344423242_16.md5
replacing old Zip file

And the md5-file does not get compressed. My code is as follows:

target = """" & path & "\" & Mid(FileName, 1, (Len
         (FileName) - 3)) & "zip"""

sourceXML = """" & path & "\" & FileName & """"

sourcemd5 = """" & path & "\" & ChecksumFile & """"

winzipstring = WinzipPath & " -min -a " & target & " " &
               sourceXML

Shell (winzipstring)
winzipstring = WinzipPath & " -min -a " & target & " " &
               sourcemd5
Shell (winzipstring)

Am I doing something wrong?
0
 
LVL 3

Accepted Solution

by:
tonydspaniard earned 100 total points
ID: 6847078
I found something even better:

http://www.btinternet.com/~richsoftcomputing/VBZip.zip

Here is your OCX and say thank you to the guy. It is free and the zip files will be able to be opened by Winzip


Its web site is this one.

http://www.richsoftcomputing.btinternet.co.uk/html/vbzip.html

But is the OCX that interest you

Take care..... forget about the other stuff. It seems that Winzip does have troubles with path names with spaces.....

Good talking to you. I know this will resolve your problem

0
 

Author Comment

by:ajohans
ID: 6847191
Absolutely amazing.
Fantastic!
Thank you VERY MUCH!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

867 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

23 Experts available now in Live!

Get 1:1 Help Now