UNZIP anywhere in 200 bytes, embedded (XP and onwards)

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mydigitalbutter
Posts: 2
Joined: 11 Aug 2024 15:54

UNZIP anywhere in 200 bytes, embedded (XP and onwards)

#1 Post by mydigitalbutter » 13 Nov 2024 20:33


ZIP self extractors are anywhere from 20kb to 300kb, so I wanted something a bit more portable.
There are two versions of the script.


Version one, unzips into the current directory

Code: Select all

Set z=CreateObject("Shell.Application")
Set x=CreateObject("Scripting.FileSystemObject")
v=x.GetFile(WScript.Arguments(0))
Set w=z.NameSpace(v).Items()
Set v=z.NameSpace(x.GetAbsolutePathName(""))
v.CopyHere w

Version two, unzips into the script directory

Code: Select all

Set z=CreateObject("Shell.Application")
Set x=CreateObject("Scripting.FileSystemObject")
v=x.GetFile(WScript.Arguments(0))
Set w=z.NameSpace(v).Items()
Set v=z.NameSpace(Left(v,InStrRev(v,"\")-1))
v.CopyHere w

The current directory and script directory are usually one and the same, but you may want to put this in a common path like system32 and call from anywhere.

Usage:
unzip file.zip
unzip.vbs file.zip
unzip.vbs path\to\file.zip

Relative paths are accepted.

Embedded example

Code: Select all

@echo off

>unzip.vbs (
echo Set z=CreateObject("Shell.Application"^)
echo Set x=CreateObject("Scripting.FileSystemObject"^)
echo v=x.GetFile(WScript.Arguments(0^)^)
echo Set w=z.NameSpace(v^).Items(^)
echo Set v=z.NameSpace(x.GetAbsolutePathName(""^)^)
echo v.CopyHere w)

unzip shareware.zip
Notice you can call unzip with/without the extension but be aware of name collisions, some extensions take precedence over vbs, ex;
unzip shareware.zip will work unless a com/exe/bat OR cmd exists by the same name (don't call unzip from unzip.cmd)
unzip.vbs shareware.zip always works.

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: UNZIP anywhere in 200 bytes, embedded (XP and onwards)

#2 Post by npocmaka_ » 18 Nov 2024 08:43

You might be interested in this: https://github.com/npocmaka/batch.scrip ... /zipjs.bat - a script that uses windows capabilities to zip/unzip files and I've wrote long ago.

Post Reply