Hi Everybody


I need to unzip a series of .zip files - all located in a folder. Each of these zip files contain only one (1) file. A series of zip file can contain between 30 and 40 zip files.

The idea is to be able to write a loop to unzip (using Winzip) the files from the zip files. This I have done - no problems here!

The problem is that the zipped filename contains a serial number which is not a part of the name of the file contained in the zipped file. I need this serial number to be included as a part of the name of the this file that is contained in the zipped file.

The code that I have used is shown below (not entirely my code)

[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 seems to work ok for unzipping files. I tried to use the optional part with the FileCopy command but what that does is that it makes a copy of the zip file and changes the extension from .zip to ".txt" thereby rendereing it unreadable and useless. What I want is to rename the just unzipped file to the name stored in the variable "strTargetFile". This variable is something like this :"ThisFilename_1234.txt".

Can anyone advise how can I catch the name of the unzipped file after the "Shell ShellStr, vbHide" command has been run?

Or any othe way that I can rename the just unzipped file to another name?

Some have used

Namespace and things like that but I don't understand how it works.

Please treat this with some degree of urgency.


Best regards and thanks in advance.



Deepak