Extracting file from a zip file

P

Paul Martin

I've successfully used Ron de Bruin's useful code for extracting a
file item from a zip file (www.rondebruin.nl/windowsxpunzip.htm).

Now, for completely unknown reasons, the code is failing.

oApp.Namespace(TEMP_FOLDER).CopyHere _
oApp.Namespace(varZipFullPath).Items.Item
(objFile.Name)

When this line of code executes, I get a Windows error (not a VBA
error) saying "the file exists." when the temp folder is in fact
empty. Even if I delete the temp folder and create a new one, this
error message appears. It has me perplexed, as it previously worked
without any such issue.

Any suggestions?

Paul Martin
Melbourne, Australia
 
P

Paul Martin

Hi Ron, code is below

Paul


Private Sub LoopThruFileItems(ByVal varZipFullPath As Variant)
' From a zip file, extract required data from multiple file items
Dim oApp As Object
Dim objFile As Object
Dim strCSVFullPath As String

Set oApp = CreateObject("Shell.Application")
TEMP_FOLDER = Environ("USERPROFILE") & "\Desktop\TEMP\"

For Each objFile In oApp.Namespace(varZipFullPath).Items
If Left(objFile.Name, 6) = "int140" Then
oApp.Namespace(TEMP_FOLDER).CopyHere _
oApp.Namespace(varZipFullPath).Items.Item(objFile.Name)

' Now I work with the file in the temp folder
End If
Next objFile
End Sub
 
P

Paul Martin

FWIW, I've modified the line that was failing with this:

oApp.Namespace(TEMP_FOLDER).CopyHere objFile

It's now working. It's a mystery why it was failing, as the code was
working originally.

Thanks anyway, Ron.

Paul
 
P

Paul Martin

Hi Ron (or anyone else)

The error has just as mysteriously returned, for reasons that I can't
determine (nothing has changed that I'm aware of).

I'm using the line of code as per the previous post, in the block of
code as previously posted. I'm getting a Windows error, "the file
exists."

Any suggestions?

Thanks in advance

Paul
 
P

Paul Martin

And it appears that "the file exists." is not because it exists in the
folder I'm defining as the temp folder, but the temp folder - Environ
("Temp") - that the zip file is copied to. It seems I need to include
the lines:

On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")
FSO.deletefolder Environ("Temp") & "\Temporary Directory*",
True

Hopefully, this is the last of the error...
 
R

Ron de Bruin

That's why it is my code example on my site <g>

Good that you have it working now

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


And it appears that "the file exists." is not because it exists in the
folder I'm defining as the temp folder, but the temp folder - Environ
("Temp") - that the zip file is copied to. It seems I need to include
the lines:

On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")
FSO.deletefolder Environ("Temp") & "\Temporary Directory*",
True

Hopefully, this is the last of the error...
 

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

Top