Hi Kenneth


I understand where you are coming from but all the functions that you have suggested use "filespec" as the input file - which I am presuming is the zipped file that I am trying to unzip, right?

Even if I get the filename and every other attribute associated with that zipped file, how do I get hold of the name of the files that are encapsulated in the zipped file.

I have attached the modified Ron's code that I am trying to use to rename the files contained in the zipped file based on some condition on the name of this encapsulated file, but it is doing is just creating another folder under the zipped file with the same name as the zipped file (without the extension) and moving all the files from the zipped file to this folder. This is not what I am looking at doing.

This is his code (modified)


[vba]
Sub Unzip1()
Dim FSO As Object
Dim oApp As Object
Dim Fname As Variant
Dim FileNameFolder As Variant
Dim DefPath As String
Dim strDate As String
Dim fileNameInZip As Variant

Fname = Application.GetOpenFilename(filefilter:="Zip Files (*.zip), *.zip", _
MultiSelect:=False)
If Fname = False Then
'Do nothing
Else
'Root folder for the new folder.
'You can also use DefPath = "C:\Users\Ron\test\"
DefPath = "D:\MyTestFolder" 'Application.DefaultFilePath
If Right(DefPath, 1) <> "\" Then
DefPath = DefPath & "\"
End If

'Create the folder name
'strDate = Format(Now, " dd-mm-yy h-mm-ss")
FileNameFolder = DefPath ' & "MyUnzipFolder " & strDate & "\"

'Make the normal folder in DefPath
'MkDir FileNameFolder

'Extract the files into the newly created folder
Set oApp = CreateObject("Shell.Application")

'oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(Fname).items


For Each fileNameInZip In oApp.Namespace(Fname).items
If LCase(fileNameInZip) Like LCase("*.xlsx") Then
oApp.Namespace(FileNameFolder).CopyHere _
oApp.Namespace(Fname).items.Item(CStr(fileNameInZip))
End If
Next fileNameInZip


'If you want to extract only one file you can use this:
'oApp.Namespace(FileNameFolder).CopyHere _
'oApp.Namespace(Fname).items.Item("test.txt")

'MsgBox "You find the files here: " & FileNameFolder

On Error Resume Next
Set FSO = CreateObject("scripting.filesystemobject")
FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True
End If
End Sub
[/vba]


Is there no other way of getting hold of the file that has just been unzipped using the command line statement to unzip the file as I have used in my original code something like this :-

[vba]
Sub UnZip_ZipFile(strZippedFileName As String, strTargetFolder As String, Optional strTargetFile As String)

Const PATHWINZIP As String = "C:\progra~1\winzip\"
Dim ShellStr As String

ShellStr = PATHWINZIP & "Winzip32 -min -e -o" _
& " " & Chr(34) & strZippedFileName & Chr(34) _
& " " & Chr(34) & strTargetFolder & Chr(34)

Shell ShellStr, vbHide

'FileCopy strTargetFolder & Dir(strTargetFolder), strTargetFolder & strTargetFile ' & ".txt"

End Sub
[/vba]

This subroutine gets called for each zipped file that is to be uncompressed and works perfectly ok except that I am not able to (because I don't know how to) rename the file as it is being uncompressed.

I surely don't quite understand this concept of .Namespace() very well at all and some help in either being able to work with the individual files encapsulated within the zipped file would be highly appreciated.



Deepak