Micro Focus QTP (UFT) Forums
Extract and save a file from zip folder using VB Script - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Extract and save a file from zip folder using VB Script (/Thread-Extract-and-save-a-file-from-zip-folder-using-VB-Script)



Extract and save a file from zip folder using VB Script - karthicksri07 - 02-08-2013

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


RE: Extract and save a file from zip folder using VB Script - Ankesh - 06-29-2016

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