Micro Focus QTP (UFT) Forums

Full Version: Extract and save a file from zip folder using VB Script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i need code to extract and save a file from zip folder using VB Script in QTP.
Could you please any one help me this.

Regards
Karthik
You can use the below code.

Code:
Function UnzipFile(zipFile,ExtractTo)
    
    'The location of the zip file.
    'ZipFile="C:\Test.Zip"
    
    'The folder the contents should be extracted to.
    'ExtractTo="C:\Test\"
    
    'If the extraction location does not exist create it.
    Set fso = CreateObject("Scripting.FileSystemObject")
    If NOT fso.FolderExists(ExtractTo) Then
       fso.CreateFolder(ExtractTo)
    End If
    
    'Extract the contants of the zip file.
    set objShell = CreateObject("Shell.Application")
    set FilesInZip=objShell.NameSpace(ZipFile).items
    objShell.NameSpace(ExtractTo).CopyHere(FilesInZip)
    Set fso = Nothing
    Set objShell = Nothing

End Function