Forum Discussion

PrecisionDan's avatar
PrecisionDan
Occasional Contributor
2 years ago

Is it possible to decide whether to replace files or skip files that already exist when unzipping

Hello,

 

I'm working on some scripts to handle unzipping .zip files from within TestComplete. I have a working script that unzips, but I'm just trying to see if there is a way to decide whether to "replace" or "skip".

 

This is my code to UnZip:

 

function UnzipFileToDirectory(zipFile, destinationDirectory){

if(zipFile == undefined || aqString["GetLength"](zipFile) < 1){
Log["Error"]("There was no zip file provided in the method parameters. Please provide one.");
return
}

//declare variables needed to unzip
var fso = Sys["OleObject"]("Scripting.FileSystemObject");
var objShell = Sys["OleObject"]("Shell.Application");

if(!fso["FolderExists"](destinationDirectory)){
fso["CreateFolder"](destinationDirectory)
}

//Copy the files in the Zip and past them in the destination directory
var filesInZip = objShell["NameSpace"](zipFile).Items();
objShell["NameSpace"](destinationDirectory).CopyHere(filesInZip);

}

Currently this code works to extract Zip files, but if there is already a file that exists with the same name as a file in the .zip file, I'll get presented with this window:

 

Unfortunately, it doesn't look like I can simply click on the buttons as I would expect, because it seem that while that message box is present, TestComplete is still  processing the line below.

 

Any help would be appreciated.