Creating a Compressed File

B

BeWyched

Hi

I have a routine that creates a compressed file using:

Open "path to folder/xyz.zip" For Output As #1
Close #1

This works perfectly fine. The xyz.zip file is created as a compressed file.

However, I see numerous forum posts that imply a Print command must be used
to print into the file header in order that the file is compressed:

Open "path to folder/xyz.zip" For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1

This also works fine but the extra Print command seems redundant. Anyone
know what it's supposed to do?

Cheers all and have a great Xmas.

BW
 
S

Stuart McCall

BeWyched said:
Hi

I have a routine that creates a compressed file using:

Open "path to folder/xyz.zip" For Output As #1
Close #1

This works perfectly fine. The xyz.zip file is created as a compressed
file.

However, I see numerous forum posts that imply a Print command must be
used
to print into the file header in order that the file is compressed:

Open "path to folder/xyz.zip" For Output As #1
Print #1, Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String(18, 0)
Close #1

This also works fine but the extra Print command seems redundant. Anyone
know what it's supposed to do?

Cheers all and have a great Xmas.

BW

It writes a header of a standard length (24 bytes) at the beginning of the
file. The first two characters are PK (most likely in deference to Phil Katz
who came up with the zip file as we know it today). I have no idea of the
significance of the next two bytes, and the 18 character 0's are just
padding, in case the space is needed in future.

Also, in case you are not aware, the Print # command appends a
carriage-return line-feed pair of characters to the string being written.
This is required for Windows to believe it's a 'legal' zip file. <shrug>

If you attempt to make use of the zip file without this header in place,
Windows will give you an error message.
 
B

BeWyched

Thanks Stuart.

Now I understand!

Interestingly, if I ignore the Print line then the compressed file does
perform properly on my Vista PC - I can copy files to it which are
compressed, then extract in the normal way - but does indeed throw a
corruption error on my XP machine. So it looks like MS have changed something
t'wixt versions.

Your post was invaluable as I was about to dump the Print line and
distribute the application to many users who still have XP or earlier.

Have a great Xmas.

BW
 
S

Stuart McCall

BeWyched said:
Thanks Stuart.

Now I understand!

Its always better to understand, rather than just to know.
Interestingly, if I ignore the Print line then the compressed file does
perform properly on my Vista PC - I can copy files to it which are
compressed, then extract in the normal way - but does indeed throw a
corruption error on my XP machine. So it looks like MS have changed
something
t'wixt versions.

Yes that's interesting. I don't have a vista as yet, so that's useful
knowledge. Thanks.
Your post was invaluable as I was about to dump the Print line and
distribute the application to many users who still have XP or earlier.

You ought to be aware that some sysadmins may 'turn off' compressed folders
for security reasons. If you run into this kind of trouble, you might want
to consider using a library instead. There's a freeware one called Zlib
which is known to work in VB, so it ought to work ok in VBA too.
Have a great Xmas.

You too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top