Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reading contents of .zip without unzipping

672 views
Skip to first unread message

ccwhite

unread,
Jan 18, 2011, 2:02:09 PM1/18/11
to
I have a .zip file that starts with a parent directory. I need to read
that dir from the file then search my HD to see if that dir name
already exists. If it exists, I then delete it and replace it the
contents of the .zip file.

All of this I can do, except read the .zip without actually unzipping
the file.

The .zip file can be upwards of 2G in size so I want to avoid
unzipping, then reading the dir, then copying.

The reason I don't just unzip directly to the location and force an
overwrite is that for some reason when using the CopyHere method to
unzip, it ignores the switches that would normally force the overwrite
and still prompts the user if they want to overwrite.

Mayayana

unread,
Jan 18, 2011, 3:01:55 PM1/18/11
to
You can certainly do it. The info. is in there.
But ZIP file format is fairly complex. If you
want to tackle it, there's a script class for handling
binary files here:

http://www.jsware.net/jsware/scripts.php5#bints

It only requires Textstream, and includes functions
for reading file headers, like converting 4 bytes to
a 32-bit integer value.

For the format docs, it looks like this might be
sufficient:

http://en.wikipedia.org/wiki/ZIP_(file_format)

James Whitlow

unread,
Jan 18, 2011, 6:56:35 PM1/18/11
to
"ccwhite" <cris.c...@gmail.com> wrote in message
news:0a6fe2bf-3ef6-4e6f...@f20g2000prn.googlegroups.com...

>I have a .zip file that starts with a parent directory. I need to read
> that dir from the file then search my HD to see if that dir name
> already exists. If it exists, I then delete it and replace it the
> contents of the .zip file.
>
> All of this I can do, except read the .zip without actually unzipping
> the file.
>
> The .zip file can be upwards of 2G in size so I want to avoid
> unzipping, then reading the dir, then copying.

You can use the 'Shell.Application object on WinXP and newer to read the
contents of a zip file.

To get a listing of the files and folders at the root of the zip file, you
can use something like:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sZipFile = "C:\TestFile.zip"

Set oShell = CreateObject("Shell.Application")
Set oZip = oShell.Namespace(sZipFile)

For Each oItem in oZip.Items
MsgBox oItem.Name, , oItem.Type
Next
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The folders should have a type of 'File Folder' and a size of 0. You can
enumerate the subfolders as well by appending their name to the zip file
itself. The one quirky thing I have found in experimenting (WinXP) with this
is that the first level subfolder off of the zip file must be delimited with
a backslash and 2nd level and deeper subfolders have to be delimited with a
forward slash. So if you have 'test.zip' with a folder called 'Level 1', you
would use 'test.zip\Level 1'. If you have a subfolder inside this one called
'Level 2', you need to use 'test.zip\Level 1/Level 2'. YMMV.


0 new messages