Option Explicit
Const strStartPath = "C:\"
Const strDestFile = "c:\output.txt"
Const strDestMP3File = "c:\outputMP3.txt"
Dim objFSO, strTempFolder, objDestFile, objDestMP3File
Set objFSO = CreateObject("Scripting.FileSystemObject")
strTempFolder = CreateTempFolder()
Dim strDest, strDestMP3
strDest = ""
strDestMP3 = ""
If objFSO.FileExists(strDestFile) Then objFSO.DeleteFile(strDestFile)
If objFSO.FileExists(strDestMP3File) Then objFSO.DeleteFile(strDestMP3File)
TraverseFolder strStartPath
msgbox "done"
objFSO.DeleteFolder(strTempFolder)
Sub TraverseFolder(strFolderPath)
Dim objCurrentFolder, objFile, objFolder
Set objCurrentFolder = objFSO.GetFolder(strFolderPath)
On Error Resume Next
For Each objFile In objCurrentFolder.Files
If Not Err Then
If LCase(objFSO.GetExtensionName(objFile)) = "zip" then
Call UnZipAndCheckExtension(objFile, strTempFolder)
End If
Else
Err.Clear
End If
Next
For Each objFolder In objCurrentFolder.subFolders
If Not Err Then
TraverseFolder objFolder.ParentFolder & "\" & objFolder.name
Else
Err.Clear
End If
Next
On Error Goto 0
End Sub
Function UnZipAndCheckExtension(strZipFile, strTempFolder)
Const strUNZIPSource = "WZUNZIP.EXE"
Dim objFSO, objShell, intRet
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strTempFolder) Then objFSO.CreateFolder (strTempFolder)
Set objShell = CreateObject("WScript.shell")
On Error Resume Next
intRet = objShell.Run("""" & strUNZIPSource & """ -o """ & strZipFile & """ """ & strTempFolder & """", _
0, True)
If Err Then
On Error Goto 0
msgbox strZipFile & vbLf & Err.Description
Exit Function
End If
On Error Goto 0
Dim objFolder, objFile
Set objFolder = objFSO.GetFolder(strTempFolder)
strDest = "The following files are found in '" & strZipFile & "':" & vbLf
strDestMP3 = "The following MP3 files are found in '" & strZipFile & "':" & vbLf
For Each objFile In objFolder.Files
strDest = strDest & "->" & objFSO.GetFileName(objFile) & vbLf
If LCase(objFSO.GetExtensionName(objFile)) = "mp3" Then
strDestMP3 = strDestMP3 & "->" & objFSO.GetFileName(objFile) & vbLf
End If
objFSO.DeleteFile(objFile)
Next
Set objDestFile = objFSO.OpenTextFile(strDestFile, 8, True)
objDestFile.Write(strDest)
objDestFile.Close
Set objDestMP3File = objFSO.OpenTextFile(strDestMP3File, 8, True)
objDestMP3File.Write(strDestMP3)
objDestMP3File.Close
End Function
Function CreateTempFolder()
Dim objFSO, strTempFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
strTempFile = objFSO.GetTempName
strTempFile = Replace(strTempFile, "." & objFSO.GetExtensionName(strTempFile), "")
Dim objShell
Set objShell = CreateObject("WScript.Shell")
CreateTempFolder = Replace(objShell.SpecialFolders("Desktop"), "Desktop", "Local Settings\Temp") & _
"\" & strTempFile
End Function
- output.txt contains all files within each zip file.
- outputMP3.txt contains only mp3 files within each zip file.
However, you MUST have an unzip utility to have this working. In this example, I used unzip.exe which is a freeware downloadable from here:
ftp://tug.ctan.org/tex-archive/tools/zip/info-zip/WIN32
- Select this one: unz552xN.exe
sew
Open in new window