I've got some code that unzips a file (supposedly). The person who
wrote it says that it works fine on his computer. I've seen it work,
too. :) However, I'm running it from my computer and I get an error
message that says "The file exists". Error occurs on this line (Watch
for word wrap):
objShellApp.NameSpace(strWorkFolder).CopyHere
objShellApp.NameSpace(strZipFilePath).Items
Has anybody used the Shell Namespace for unzipping before? And if
sso, would you please point out why this might not work? I'm running
XP Professional with all the latest updates.
Public Sub Extract()
'Declare variables
Dim objFileSystem
Dim workFolder As Folder
Dim workFile As File
Dim objShellApp
Dim strUcaseFileName As String
Dim strZipFilePath, strWorkFolder
'Initialize objects
Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set workFolder = objFileSystem.GetFolder(strWorkPath)
Set objShellApp = CreateObject("Shell.Application")
For Each workFile In workFolder.Files
strUcaseFileName = UCase(workFile.Name)
If (Mid(strUcaseFileName, 1, 2) = "PS" Or _
Mid(strUcaseFileName, 1, 3) = "TLD" _
Or Mid(strUcaseFileName, 1, 2) = "RP" Or Right(strUcaseFileName, 4) =
".ZIP") Then
objFileSystem.DeleteFile (strWorkPath & workFile.Name)
End If
Next
'Copy the file with unit extension to work
'directory with the name work.zip
'for processing the zip file. Assign the
'complete path of the file to a variable
objFileSystem.CopyFile strLEWkPath & Infilename, strWorkPath &
"work.zip"
'ShellApp.Namespace is not able
'to accept string type variables.
'hence we are taking a variant type local variables
'to hold work folder path and zip file name and path
strZipFilePath = strWorkPath & "work.zip"
strWorkFolder = strWorkPath & "Extract"
strWorkFolder = strWorkPath
'Use Shell.Application object's "Copyhere"
'method to extract files from the zip file
'this depends on the default file extraction
'capability of windows it works in XP
'********Important*********** This code will not
'work on windows 2000 Pro.
objShellApp.NameSpace(strWorkFolder).CopyHere
objShellApp.NameSpace(strZipFilePath).Items
Set objFileSystem = Nothing
Set objShellApp = Nothing
End Sub