Sunday, March 9, 2014

WshShell | Code to Extract ZIP file

Function ExtractZIP(zipFilePath)
Dim arrFile, pathToZipFile, extractTo

arrFile = Split(zipFilePath, ".")     ' Split file path with file extension
Set fso = CreateObject("Scripting.FileSystemObject")    ' Create fso object to create/delete intermediate files...etc.,
fso.CreateFolder(arrFile(0) & "\")     'creating a folder with same name and location
pathToZipFile= arrFile(0) & ".zip"
extractTo= arrFile(0) & "\"

set objShell = CreateObject("Shell.Application")     'creating shell object
        ' code to extract the zip file and copy to same specified folder
set filesInzip=objShell.NameSpace(pathToZipFile).items
objShell.NameSpace(extractTo).CopyHere(filesInzip)
Wait(2)
'fso.DeleteFile pathToZipFile, True    ' deleting zip file after the extraction.
Set fso = Nothing
Set objShell = Nothing
End Function

No comments:

Post a Comment