8

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.

Code to unzip files:

 Set objSA = CreateObject("Shell.Application")
 Set objSource = objSA.NameSpace(pathToZipFile).Items ()
 Set objTarget = objSA.NameSpace(extractTo)     

 objTarget.CopyHere objSource,4
Helen
  • 87,344
  • 17
  • 243
  • 314
ccwhite
  • 125
  • 1
  • 4

4 Answers4

2

You can use For Each on your objSource object, for example:

Dim objSA, objSource, item
Set objSA = CreateObject("Shell.Application")
Set objSource = objSA.NameSpace(pathToZipFile).Items ()
For Each item in objSource
    WScript.Echo item
Next 
Stephen Quan
  • 21,481
  • 4
  • 88
  • 75
1

Here is a similar question on SO.
How to list the contents of a .zip folder in c#?

I've used this library myself. It works well, http://dotnetzip.codeplex.com/, there is even a treeview example that appears to read the zip without extraction.

You will need the DLLs on the server, but I wouldn't say you have to install them. ;)

Community
  • 1
  • 1
Doug Chamberlain
  • 11,192
  • 9
  • 51
  • 91
0

I'm not sure if it is possible to read the contents of a zip without extracting it.

If you are just trying to avoid a time consuming copy operation on the data you could try unzipping to a temp directory and then using a "move" function. Move is usually less time consuming than copy as it doesn't actually re-write the data on the disk. It just updates the file system to point at where the data is.

David Turvey
  • 2,891
  • 6
  • 27
  • 29
  • Everything I have tried does not work. The problem is that I can have 10 .zip files (software patches) that need to be applied sequentially. If the system to be patched already has patches 1-5, then I don't need to waste the time doing the unzip, check, delete, try next. As it stands, that may be what I end up doing. Either that or convincing the customer that its ok if the users have to hit a button to confirm a overwrite. – ccwhite Jan 19 '11 at 19:52
  • Can you not determine the patch version from the filename of the zip file? Just name the zips something sensible. – David Turvey Jan 19 '11 at 21:10
  • I wish it was that simple. Each patch has a different starting directory under the zip, that often is not related to the actual patch name. – ccwhite Feb 02 '11 at 16:44
0

Assuming that you can use an external application, try downloading 7Zip and then have your script execute it with the -l switch. This should give you some output that you should be able to parse in some way.

Sample from the help file: 7z l archive.zip

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
  • I think I got this to a semi working state. Still working on it but this seems the most promising – ccwhite Feb 02 '11 at 16:45