You are here

How to unzip using TestComplete JavaScript

If you nned to extract a zipped file. Here is a script doing it nice and easy. It does use the Scripting.FileSystemObject, But it is nicely put together, and easy to use.


function testUnzip()
{
//Specifies the location of the zip file.
var ZipFile = "C:\\temp\\temp.zip";
//Specifies the folder the contents should be extracted to.
var ExtractTo = "C:\\temp";
// If the extraction location does not exist, create it.
var fso = new ActiveXObject("Scripting.FileSystemObject");
// Creates the Extract to folder, if it does not excist
if ( !fso.FolderExists(ExtractTo) ){
fso.CreateFolder(ExtractTo);
}

//Extract the contents of the zip file.
var objShell = new ActiveXObject("Shell.Application");
var FilesInZip = objShell.NameSpace(ZipFile).Items();

objShell.NameSpace(ExtractTo).CopyHere(FilesInZip);
// Destroying file system object
fso = null;
// Destroying
objShell = null;
}