Forum Discussion
- nicktulettContributorOne way would be to install 7-Zip
Then include 7z.exe as a TestedApp.
Routine to extract a zip file would then be:
TestedApps.UNZIP.Params.SimpleParams.CommandLineParameters = 'x "' + zipFile + '" -o' + outputFolder + ' -aoa';
var unzipper = TestedApps.unzipLatestBuild.Run();
while (unzipper.Exists) {
delay(10e3);
}
Hi Luo,
An example demonstrating how to extract zip files without using a third-party utility has been posted here.
- TonyMroOccasional Contributor'=================================
' Function: ExtractCompressedFiles(ByVal sSourceFile as STRING, ByVal sTargetDir as STRING) as BOOLEAN
'
' DESCRIPTION:
' This function extracts all files from a compressed "folder" (ZIP, CAB, etc.) using the Windows Shell
' Folders' CopyHere method (http://msdn2.microsoft.com/en-us/library/ms723207.aspx). All files and folders
' will be extracted from the ZIP file. A progress bar will be displayed.
'
' SCOPE: Public
' PARAMETERS: STRING sSourceFile fully qualified path of the compressed file
' STRING sTargetDir fully qualified path of the destination folder
' RETURNS: BOOLEAN TRUE = compressed file successfully extracted
' FALSE = compressed file could not be extracted
' ERRORS: Error message posted in results log(s) if specified compressed file does not exist.
' REVISION HISTORY:
' 09/09/06 A. Mrozinski Created.
'=================================
Public Function ExtractCompressedFiles(ByVal sSourceFile, ByVal sTargetDir)
Dim oFS, oShell, oSource, oTarget
ExtractCompressedFiles = FALSE
Set oFS = CreateObject("Scripting.FileSystemObject")
If oFS.FileExists(sSourceFile) Then
If NOT oFS.FolderExists(sTargetDir) Then
oFS.CreateFolder(sTargetDir)
' create it and return TRUE
If NOT oFS.FolderExists(sTargetDir) Then
LogFail "ExtractCompressedFiles", "Specified target directory " & sTargetDir & " could not be created."
Set oFS = Nothing
Exit Function
End If
End If
' Create the required Shell objects
Set oShell = CreateObject("Shell.Application")
' Create a reference to the files and folders in the compressed file
Set oSource = oShell.NameSpace(sSourceFile).Items()
' Create a reference to the target folder
Set oTarget = oShell.NameSpace(sTargetDir)
' These are the pertinent CopyHere options, according to MSDN (http://msdn2.microsoft.com/en-us/library/ms723207.aspx).
' 4: Do not display a progress dialog box.
' 256: Display a progress dialog box but do not show the file names.
' Extract the files
oTarget.CopyHere oSource, 256
' Release the objects
Set oSource = Nothing
Set oTarget = Nothing
Set oShell = Nothing
ExtractCompressedFiles = TRUE
Else
LogFail "ExtractCompressedFiles", "Compressed file " & sSourceFile & " was not found."
End If
Set oFS = Nothing
End Function
Hi Tony,
Thanks for your example. I've formatted it if you don't mind:
'=================================
' Function: ExtractCompressedFiles(ByVal sSourceFile as STRING, ByVal sTargetDir as STRING) as BOOLEAN ' ' DESCRIPTION: ' This function extracts all files from a compressed "folder" (ZIP, CAB, etc.) using the Windows Shell ' Folders' CopyHere method (http://msdn2.microsoft.com/en-us/library/ms723207.aspx). All files and folders ' will be extracted from the ZIP file. A progress bar will be displayed. ' ' SCOPE: Public ' PARAMETERS: STRING sSourceFile fully qualified path of the compressed file ' STRING sTargetDir fully qualified path of the destination folder ' RETURNS: BOOLEAN TRUE = compressed file successfully extracted ' FALSE = compressed file could not be extracted ' ERRORS: Error message posted in results log(s) if specified compressed file does not exist. ' REVISION HISTORY: ' 09/09/06 A. Mrozinski Created.
'=================================
Public Function ExtractCompressedFiles(ByVal sSourceFile, ByVal sTargetDir)
Dim oFS, oShell, oSource, oTarget
ExtractCompressedFiles = FALSE
Set oFS = CreateObject("Scripting.FileSystemObject")
If oFS.FileExists(sSourceFile) Then
If NOT oFS.FolderExists(sTargetDir) Then
oFS.CreateFolder(sTargetDir) ' create it and return TRUE
If NOT oFS.FolderExists(sTargetDir) Then
LogFail "ExtractCompressedFiles", "Specified target directory " & sTargetDir & " could not be created."
Set oFS = Nothing
Exit Function
End If
End If ' Create the required Shell objects
Set oShell = CreateObject("Shell.Application") ' Create a reference to the files and folders in the compressed file
Set oSource = oShell.NameSpace(sSourceFile).Items() ' Create a reference to the target folder
Set oTarget = oShell.NameSpace(sTargetDir)
' These are the pertinent CopyHere options, according to MSDN (http://msdn2.microsoft.com/en-us/library/ms723207.aspx).
' 4: Do not display a progress dialog box.
' 256: Display a progress dialog box but do not show the file names.
' Extract the files
oTarget.CopyHere oSource, 256
' Release the objects
Set oSource = Nothing
Set oTarget = Nothing
Set oShell = Nothing
ExtractCompressedFiles = TRUE
Else
LogFail "ExtractCompressedFiles", "Compressed file " & sSourceFile & " was not found."
End If
Set oFS = Nothing
End Function
- TonyMroOccasional ContributorHi Tanya,
Thanks for formatting the code in my post. What is the process for formatting code in a post?
Tony,
At the moment, only manual formatting is possible. Actually, you can use the code BBCode. However, it doesn't work as expected sometimes - so, it's not currently reliable.