Forum Discussion

poffin's avatar
poffin
Occasional Contributor
9 years ago

Unzipping .zip files

I need to be able to either inspect the contents of a zip file or unzip the file & then read contents for testing a desktop application. I'm using javascript in my project. Can anyone point me in the right direction?

  • If you have any more specific details on what you are trying to do and what you have already tried, then perhaps there will be more specific suggestions to offer!


  • poffin wrote:

     

    I get an error: "ReferenceError ActiveXObject is not defined".


    If you use JavaScript (not JScript), replace

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

    with

    var fso = Sys.OleObject("Scripting.FileSystemObject");
    ...
    var objShell = Sys.OleObject("Shell.Application");
    • poffin's avatar
      poffin
      Occasional Contributor

      Thank you for your reply. Unfortunately it's not very helpful! The information is convoluted, and somewhat inaccurate. Most examples are using 3rd party software (7zip) or in VBScript. There is one example from those links that I've already tried:

       

       //Specifies the location of the zip file.
        var ZipFile = "D:\\Test\\Test.zip";
      
      
        //Specifies the folder the contents should be extracted to. 
        var ExtractTo = "D:\\Test";
      
      
        // If the extraction location does not exist, create it. 
        var fso = new ActiveXObject("Scripting.FileSystemObject"); 
      
        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);
      
        fso = null;
        objShell = null;

      However it appears as though this was incorrect, because I get an error: "ReferenceError ActiveXObject is not defined". If you have any more specific advice, I would be grateful.

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        poffin wrote:

         

        I get an error: "ReferenceError ActiveXObject is not defined".


        If you use JavaScript (not JScript), replace

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

        with

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