sloppycode.net
Munzip - mass unzip files
Unzip many files with the Exceed unzip library.
Home
›
Code snippets
›
Misc
›
Munzip - mass unzip files
By Jonah R. Goldberg. Munzip was created to solve the problem handling MANY zip files with a single command. The exceed zip library is required, from
here
'******************************* '* Munzip.VBS '* Jonah R. Goldberg '* Feb 2002 '* Distribute Freely, However has a dependency on Xceed ZIP Library. :) '******************************* '* Munzip was created to solve the problem handling MANY zip files '* with a single command. '* '* Correct Usage --> Munzip [dir of zips to unzip] '* [optional: directory to unzip to (defaults to current dir)] '* [optional: separate dir per zip(yes:no) default:no] '* [optional: File Log? (yes:no) default:no] '******************************* Dim oFS Dim oFile Dim oFiles Dim oFolder Dim oSubFolder Dim oZipFactory Dim bLogging Dim oLog Dim bSeparateFolders Dim sFolderToUnzip Dim sFolderToUnzipTo CONST bDebug = True CONST USAGE_STATEMENT = "Correct Usage: Munzip [dir of zips to unzip] [optional: directory to unzip to (defaults to current dir)] [optional: separate dir per zip(yes:no) default:no] [optional: File Log? (yes:no) default:no]" set oZipFactory = CreateObject("XceedSoftware.XceedZip") Set oFS = CreateObject("Scripting.FileSystemObject") Set oArgs = WScript.Arguments nArgsCount = oArgs.Count 'Defaults bSeparateFolders = False bLogging = False if bLogging Then Set oLog = oFS.OpenTextFile(".\munzip.log", 8 , true, 0) For i = 0 to oArgs.Count - 1 LogMessage "Arg " & CStr(i) & " - " & oArgs(i) Next End if If nArgsCount < 1 Then LogMessage USAGE_STATEMENT WScript.Quit End If if nArgsCount > 2 Then If LCase(left(oArgs.item(2),1)) = "y" then bSeparateFolders = True LogMessage "Separate Folders Requested." End If End if if nArgsCount > 3 Then If LCase(left(oArgs.item(3),1)) = "y" then bLogging = True LogMessage "Logging Requested." End If End if 'Get Source Folder sFolderToUnzip = oArgs.item(0) 'Check for Validity if Not oFS.FolderExists(sFolderToUnzip) Then LogMessage(sFolderToUnzip & " DOESN'T EXIST... EXITING!") WScript.Quit End if if nArgsCount > 1 then 'Get Destination Folder sFolderToUnzipTo = oArgs.item(1) 'Check for Validity if Not oFS.FolderExists(sFolderToUnzipTo) Then LogMessage(sFolderToUnzipTo & " DOESN'T EXIST... EXITING!") WScript.Quit End if Else sFolderToUnzipTo = "." End If If right(sFolderToUnzip, 1) <> "\" then sFolderToUnzipTo = sFolderToUnzipTo & "\" End if Set oFolder = oFS.GetFolder(sFolderToUnzip) Set oFiles = oFolder.Files oZipFactory.UnzipToFolder = sFolderToUnzipTo For Each oFile in oFiles sFileName = oFile.Name if LCase(Right(sFileName,3)) = "zip" Then if bSeparateFolders Then sUnzippingFolder = sFolderToUnzipTo & Left(sFileName, len(sFileName) - 4) & "\" if Not oFS.FolderExists(sUnzippingFolder) then if Err.Number <> 0 Then LogMessage "Err: Folder " & sUnzippingFolder LogMessage Err.Description Err.Clear End if oFS.CreateFolder(sUnzippingFolder) if bDebug Then LogMessage "Creating Folder " & sUnzippingFolder End if if Err.Number <> 0 Then LogMessage Err.Description Err.Clear oZipFactory.UnzipToFolder = sFolderToUnzipTo Else oZipFactory.UnzipToFolder = sUnzippingFolder End if 'Folder Already Exists Else if bDebug Then LogMessage "Folder " & sUnzippingFolder & " Exists." End if oZipFactory.UnzipToFolder = sUnzippingFolder End if End if oZipFactory.ZipFilename = sFolderToUnzipTo & sFileName nResCode = oZipFactory.unzip if nResCode = 0 Then LogMessage (oFile.Name & " unzipped to " & oZipFactory.UnzipToFolder) Else LogMessage ("Error " & CStr(nResCode) & " encountered when unzipping " & oFile.Name & " to " & sFolderToUnzip) End if End if Next LogMessage ("Process Ended " & Now()) If bLogging Then oLog.close Set oLog = Nothing End if Set oFS = Nothing Set oFile = Nothing Set oFiles = Nothing Set oFolder = Nothing Set oZipFactory = Nothing Set oArgs = Nothing WScript.Quit Sub LogMessage(sMsg) WScript.Echo Now() & " - " & sMsg If bLogging Then oLog.writeline Now() & " - " & sMsg End If End Sub
{Name}
Says:
{Date}
{Text}
› Home
› C#
› Snippets
› Articles
› Tools
› Taglines
› ASP
› Dictionary Object
› FSO
› Unix cheat sheet
› Gaming
› CSS
› Yak
› Umbraco
› About
› Contact
› Privacy
› Projects
› Search