Forum Discussion

PrecisionDan's avatar
PrecisionDan
Occasional Contributor
2 years ago

Is it possible to unzip a compressed folder through a TestComplete script (c#Script)

Hello,

 

I've got a .zip stored locally that I'm hoping I can unzip and open using testcomplete. I have had an explore around the aqFileSystem and aqFile objects but haven't been able to work anything out in my scripts. I did stumble upon a forum post from 2011 (https://community.smartbear.com/t5/TestComplete-Questions/How-to-extract-a-zip-file-and-Can-we-hide-the-password-that-we/td-p/52237/page/2) but the method they are indicating to use seems to not work anymore.

 

Any guidance I can get to take the .zip and unzip it so I can interact with the contents inside would be amazing.

 

Kind regards,

Dan

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Yes. You can use the following code - provide the appropriate command and parameters of the application, and pass it into Exec method.

     

     

    function Test()
    {
        var oExec = WshShell.Exec("zip command goes here"); 
        while (oExec.Status == 0) {
            aqUtils.Delay(1000);
        }
        while (!oExec.StdOut.AtEndOfStream) {
            Log.Message(oExec.StdOut.ReadLine());
        }
    }

     

     

    For example,

     

    // Decompressing files without asking for confirmation to replace
    "D7Zip.exe -u ""c:\fileout.zip"" -f ""c:\folderout\"" -r"
    // Extracts all *.gif files
    "unrar x c:\yourfile.rar *.gif c:\extractfolder\"

     

  • PrecisionDan's avatar
    PrecisionDan
    Occasional Contributor

    Thank you for the help here. I also found another solution to this in one of the comments here: https://community.smartbear.com/t5/TestComplete-Questions/Unzipping-zip-files/m-p/125798/highlight/true#M14273 

    Basically, I needed to replace 

    var fso = new ActiveXObject("Scripting.FileSystemObject");

     with 

    var objShell = new ActiveXObject("Shell.Application");

     

    and 

    var fso = Sys.OleObject("Scripting.FileSystemObject")

     

    with 

     

    var objShell = Sys.OleObject("Shell.Application");