This project is read-only.

Output from a single zip to multiple folders

Jun 5, 2008 at 6:04 PM

This is not a bug, I am sure, but just my own stupidity: in VB 2005 I am trying to loop through a zip file created elsewhere, and most likely with another archive utility. This works fine for most part, but when I try to test an 
I get an exception thrown telling me I ought to use the "new" keyword - which does not make sense because the archive at that point is already open. My problem is that I need to unzip some files into one location (with or without pathname) and some into another.

Hope someone can help me figure out what I am doing wrong.


Jun 5, 2008 at 11:03 PM
could be a bug, ya never know!
for the exception, can you show me more of the code, and all of the error message?
Jun 6, 2008 at 1:57 AM

Thanks, Cheeso, but I still think this is my mistake - until you really tell me otherwise. NB: the line in bold is what I mentioned earlier on .Item - in my humble opinion - would be better served if it accepted a numerical value as override - but that's just me..

The resulting exception:
Extraction failed: Object reference not set to an instance of an object. (Dr Peter Rorlach)

The code producint the error happens on the bold line - the passed variables have been checked and double-checked and they are correct in their values:
For I = 0 To .EntryFilenames.Count - 1
tmpZipFile = .EntryFilenames(I).ToLower
If getExt(tmpZipFile) = "sc4lot" Or getExt(tmpZipFile) = "sc4desc" Or getExt(tmpZipFile) = "sc4model" Or getExt(tmpZipFile) = "dat" Then
    .Extract(tmpZipFile, destFolder.Text, True)
zItem = .Item(tmpZipFile)
    If Not zItem.IsDirectory Then
        .Extract(tmpZipFile, destinationFolder, True)
    End If
End If
N = N + 1
If sProg.Value < sProg.Maximum Then
    sProg.Value = sProg.Value + 1
    sProg.Value = 0
End If

Thanks for your efforts.


Jun 6, 2008 at 7:10 AM

did you just try a foreach loop?
it seems you're taking the roundabout way . . .
Could you do something like this?

         Using zip As ZipFile = ZipFile.Read(ZipFileToExtract)
               Dim e As ZipEntry
               For Each e In zip
                  dim entryName as string
                  entryName = e.Filename
                  If getExt(entryName) = "sc4lot" Or getExt(entryName) = "sc4desc" Or getExt(entryName) = "sc4model" Or getExt(entryName) = "dat" Then
                     e.Extract(destFolder.Text, True)
If Not e.IsDirectory Then
e.Extract(destFolder.Text, True)
End If End If                Next          End Using

what your code is doing might yet be a bug, but still it seems an indirect and unnecessarily complex way to manipulate the zip archive.

Jun 6, 2008 at 9:25 AM
Edited Jun 6, 2008 at 9:58 AM
Thanks Cheeso,

That, with a minor change (e has to be renamed and declared outside enclosing blocks) di indeed work - so no bug, just an old man's not-seeing-the-trees-for-the-forrest kind of stupidity..

Thanks again.

Peter R.