#pragma rtGlobals=3 // Use modern global access method and strict wave access. Function CreateZipjsbat() //from https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/zipjs.bat //how to use see //http://stackoverflow.com/questions/28043589/how-can-i-compress-zip-and-uncompress-unzip-files-and-folders-with-bat // this is short summary of the description there. Can unzpi, zip and do much more... // //// unzip content of a zip to given folder.content of the zip will be not preserved (-keep no).Destination will be not overwritten (-force no) //call zipjs.bat unzip -source C:\myDir\myZip.zip -destination C:\MyDir -keep no -force no // //// lists content of a zip file and full paths will be printed (-flat yes) //call zipjs.bat list -source C:\myZip.zip\inZipDir -flat yes // //// lists content of a zip file and the content will be list as a tree (-flat no) //call zipjs.bat list -source C:\myZip.zip -flat no // //// prints uncompressed size in bytes //zipjs.bat getSize -source C:\myZip.zip // //// zips content of folder without the folder itself //call zipjs.bat zipDirItems -source C:\myDir\ -destination C:\MyZip.zip -keep yes -force no // //// zips file or a folder (with the folder itslelf) //call zipjs.bat zipItem -source C:\myDir\myFile.txt -destination C:\MyZip.zip -keep yes -force no // //// unzips only part of the zip with given path inside //call zipjs.bat unZipItem -source C:\myDir\myZip.zip\InzipDir\InzipFile -destination C:\OtherDir -keep no -force yes //call zipjs.bat unZipItem -source C:\myDir\myZip.zip\InzipDir -destination C:\OtherDir // //// adds content to a zip file //call zipjs.bat addToZip -source C:\some_file -destination C:\myDir\myZip.zip\InzipDir -keep no //call zipjs.bat addToZip -source C:\some_file -destination C:\myDir\myZip.zip String nb = "zipjsbat" NewNotebook/N=$nb/F=0/V=0/K=1/W=(321,81.5,820.5,376.25) Notebook $nb defaultTab=20, statusWidth=252 Notebook $nb font="Arial", fSize=10, fStyle=0, textRGB=(0,0,0) Notebook $nb text="@if (@X)==(@Y) @end /* JScript comment\r" Notebook $nb text="\t@echo off\r" Notebook $nb text="\t\r" Notebook $nb text="\trem :: the first argument is the script name as it will be used for proper help message\r" Notebook $nb text="\tcscript //E:JScript //nologo \"%~f0\" \"%~nx0\" %*\r" Notebook $nb text="\r" Notebook $nb text="\texit /b %errorlevel%\r" Notebook $nb text="\t\r" Notebook $nb text="@if (@X)==(@Y) @end JScript comment */\r" Notebook $nb text="\r" Notebook $nb text="\r" Notebook $nb text="/*\r" Notebook $nb text="Compression/uncompression command-line tool that uses Shell.Application and WSH/Jscript -\r" Notebook $nb text="http://msdn.microsoft.com/en-us/library/windows/desktop/bb774085(v=vs.85).aspx\r" Notebook $nb text="\r" Notebook $nb text="Some resources That I've used:\r" Notebook $nb text="http://www.robvanderwoude.com/vbstech_files_zip.php\r" Notebook $nb text="https://code.google.com/p/jsxt/source/browse/trunk/js/win32/ZipFile.js?r=161\r" Notebook $nb text="\r" Notebook $nb text="\r" Notebook $nb text="\r" Notebook $nb text="\r" Notebook $nb text="UPDATE *17-03-15*\r" Notebook $nb text="\r" Notebook $nb text="Devnullius Plussed noticed a bug in ZipDirItems and ZipItem functions (now fixed)\r" Notebook $nb text="And also following issues (at the moment not handled by the script):\r" Notebook $nb text="- if there's not enough space on the system drive (usually C:\\) the script could produce various errors " Notebook $nb text=", most often the script halts.\r" Notebook $nb text="- Folders and files that contain unicode symbols cannot be handled by Shell.Application object.\r" Notebook $nb text="\r" Notebook $nb text="UPDATE *24-03-15*\r" Notebook $nb text="\r" Notebook $nb text="Error messages are caught in waitforcount method and if shuch pops-up the script is stopped.\r" Notebook $nb text="As I don't know hoe to check the content of the pop-up the exact reason for the failure is not given\r" Notebook $nb text="but only the possible reasons.\r" Notebook $nb text="\r" Notebook $nb text="------\r" Notebook $nb text="It's possible to be ported for C#,Powershell and JScript.net so I'm planning to do it at some time.\r" Notebook $nb text="\r" Notebook $nb text="For sure there's a lot of room for improvements and optimization and I'm absolutely sure there are some " Notebook $nb text="bugs\r" Notebook $nb text="as the script is big enough to not have.\r" Notebook $nb text="\r" Notebook $nb text="\r" Notebook $nb text="\r" Notebook $nb text="!!!\r" Notebook $nb text="For suggestions contact me at - npocmaka@gmail.com\r" Notebook $nb text="!!!\r" Notebook $nb text="\r" Notebook $nb text="*/\r" Notebook $nb text="\r" Notebook $nb text="\r" Notebook $nb text="//////////////////////////////////////\r" Notebook $nb text="// CONSTANTS\r" Notebook $nb text="\r" Notebook $nb text="// TODO - Shell.Application and Scripting.FileSystemObject objects could be set as global variables to a" Notebook $nb text="void theit creation\r" Notebook $nb text="// in every method.\r" Notebook $nb text="\r" Notebook $nb text="//empty zip character sequense\r" Notebook $nb text="var ZIP_DATA= \"PK\" + String.fromCharCode(5) + String.fromCharCode(6) + \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0" Notebook $nb text="\\0\\0\";\r" Notebook $nb text="\r" Notebook $nb text="var SLEEP_INTERVAL=200;\r" Notebook $nb text="\r" Notebook $nb text="//copy option(s) used by Shell.Application.CopyHere/MoveHere\r" Notebook $nb text="var NO_PROGRESS_BAR=4;\r" Notebook $nb text="\r" Notebook $nb text="\r" Notebook $nb text="//oprions used for zip/unzip\r" Notebook $nb text="var force=true;\r" Notebook $nb text="var move=false;\r" Notebook $nb text="\r" Notebook $nb text="//option used for listing content of archive\r" Notebook $nb text="var flat=false;\r" Notebook $nb text="\r" Notebook $nb text="var source=\"\";\r" Notebook $nb text="var destination=\"\";\r" Notebook $nb text="\r" Notebook $nb text="var ARGS = WScript.Arguments;\r" Notebook $nb text="var scriptName=ARGS.Item(0);\r" Notebook $nb text="\r" Notebook $nb text="//\r" Notebook $nb text="//////////////////////////////////////\r" Notebook $nb text="\r" Notebook $nb text="//////////////////////////////////////\r" Notebook $nb text="// ADODB.Stream extensions\r" Notebook $nb text="\r" Notebook $nb text="if ( ! this.ADODB ) {\r" Notebook $nb text="\tvar ADODB = {};\r" Notebook $nb text="}\r" Notebook $nb text="\r" Notebook $nb text="if ( ! ADODB.Stream ) {\r" Notebook $nb text="\tADODB.Stream = {};\r" Notebook $nb text="}\r" Notebook $nb text="\r" Notebook $nb text="// writes a binary data to a file\r" Notebook $nb text="if ( ! ADODB.Stream.writeFile ) {\r" Notebook $nb text="\tADODB.Stream.writeFile = function(filename, bindata)\r" Notebook $nb text="\t{\r" Notebook $nb text=" var stream = new ActiveXObject(\"ADODB.Stream\");\r" Notebook $nb text=" stream.Type = 2;\r" Notebook $nb text=" stream.Mode = 3;\r" Notebook $nb text=" stream.Charset =\"ASCII\";\r" Notebook $nb text=" stream.Open();\r" Notebook $nb text=" stream.Position = 0;\r" Notebook $nb text=" stream.WriteText(bindata);\r" Notebook $nb text=" stream.SaveToFile(filename, 2);\r" Notebook $nb text=" stream.Close();\r" Notebook $nb text="\t\treturn true;\r" Notebook $nb text="\t};\r" Notebook $nb text="}\r" Notebook $nb text="\r" Notebook $nb text="//\r" Notebook $nb text="//////////////////////////////////////\r" Notebook $nb text="\r" Notebook $nb text="//////////////////////////////////////\r" Notebook $nb text="// common\r" Notebook $nb text="\r" Notebook $nb text="if ( ! this.Common ) {\r" Notebook $nb text="\tvar Common = {};\r" Notebook $nb text="}\r" Notebook $nb text="\r" Notebook $nb text="if ( ! Common.WaitForCount ) {\r" Notebook $nb text="\tCommon.WaitForCount = function(folderObject,targetCount,countFunction){\r" Notebook $nb text="\t\tvar shell = new ActiveXObject(\"Wscript.Shell\");\r" Notebook $nb text="\t\twhile (countFunction(folderObject) < targetCount ){\r" Notebook $nb text="\t\t\tWScript.Sleep(SLEEP_INTERVAL);\r" Notebook $nb text="\t\t\t//checks if a pop-up with error message appears while zipping\r" Notebook $nb text="\t\t\t//at the moment I have no idea how to read the pop-up content\r" Notebook $nb text="\t\t\t// to give the exact reason for failing\r" Notebook $nb text="\t\t\tif (shell.AppActivate(\"Compressed (zipped) Folders Error\")) {\r" Notebook $nb text="\t\t\t\tWScript.Echo(\"Error While zipping\");\r" Notebook $nb text="\t\t\t\tWScript.Echo(\"\");\r" Notebook $nb text="\t\t\t\tWScript.Echo(\"Possible reasons:\");\r" Notebook $nb text="\t\t\t\tWScript.Echo(\" -source contains filename(s) with unicode characters\");\r" Notebook $nb text="\t\t\t\tWScript.Echo(\" -produces zip exceeds 8gb size (or 2,5 gb for XP and 2003)\");\r" Notebook $nb text="\t\t\t\tWScript.Echo(\" -not enough space on system drive (usually C:\\\\)\");\r" Notebook $nb text="\t\t\t\tWScript.Quit(432);\r" Notebook $nb text="\t\t\t}\r" Notebook $nb text="\t\t\t\r" Notebook $nb text="\t\t}\r" Notebook $nb text="\t}\r" Notebook $nb text="}\r" Notebook $nb text="\r" Notebook $nb text="if ( ! Common.getParent ) {\r" Notebook $nb text="\tCommon.getParent = function(path){\r" Notebook $nb text="\t\tvar splitted=path.split(\"\\\\\");\r" Notebook $nb text="\t\tvar result=\"\";\r" Notebook $nb text="\t\tfor (var s=0;s