Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
function unzip(zipfile,extractpath){
     var fso = new ActiveXObject('Scripting.FileSystemObject');
     var oShell = new ActiveXObject('Shell.Application');
     var dst,zip;
     dst = shell.NameSpace(fso.getFolder(extractpath).Path);
      zip = shell.NameSpace(fso.getFile(zipfile).Path);
      for (var i=0; i<zip.Items().Count; i++) {
           try {
            if (fso.FileExists(zipfile)) {
                WSH.Stdout.Write('Unzipping ' + zip.Items().Item(i) + '... ');
                dst.CopyHere(zip.Items().Item(i), 4 + 16);
                WSH.Echo('Done.');
            }
        }
        catch(e) {
            WSH.Echo('Failed: ' + e);
        }
    var zipfile = WSH.Arguments(0),
dest = zipfile.replace(/\.\w+$/, '\\');

unzip(zipfile, dest);
          
          }


What I have tried:

This code is showing error as ActiveXObject doesnt have a constructor.
What is missing in the code?
Posted
Comments
ZurdoDev 3-Mar-16 7:37am    
This will only work in IE. However, you need to give the exact error message.
Member 12242930 4-Mar-16 0:37am    
Is there not a single person to help me with this?
gdaniloff 24-Mar-17 4:39am    
function unzip(zipfile,extractpath){
var fso = new ActiveXObject('Scripting.FileSystemObject');
var oShell = new ActiveXObject('Shell.Application');
var dst,zip;
dst = oShell.NameSpace(fso.getFolder(extractpath).Path);
zip = oShell.NameSpace(fso.getFile(zipfile).Path);
for (var i=0; i<zip.Items().Count; i++) {
try {
if (fso.FileExists(zipfile)) {
WSH.Stdout.Write('Unzipping ' + zip.Items().Item(i) + '... ');
dst.CopyHere(zip.Items().Item(i), 4 + 16);
WSH.Echo('Done.');
}
}
catch(e) {
WSH.Echo('Failed: ' + e);
}
}
}

var zipfile = WSH.Arguments(0);
WSH.Echo(zipfile);
dest = zipfile.replace(/\.\w+$/, '\\');
WSH.Echo('dest=['+dest+']');
unzip(zipfile, dest);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900