Skip to content

Instantly share code, notes, and snippets.

@gjyoung1974
Created October 23, 2016 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjyoung1974/58f191c49dd76c0c654e352427c6d6f2 to your computer and use it in GitHub Desktop.
Save gjyoung1974/58f191c49dd76c0c654e352427c6d6f2 to your computer and use it in GitHub Desktop.
JScript create a zip file of a log directory in MSFT Windows
// create a zip file of the log directory..
function f_CreateZip() {
var shell = new ActiveXObject("Shell.Application");
var fs_obj = new ActiveXObject("Scripting.FileSystemObject");
var zipFilename = strLogPath.path + '\\' + sActiveConfig + '-LogFiles.zip';
// create an empty zipfile :-)
var zipFile = fs_obj.CreateTextFile(zipFilename, 1, 0);
zipFile.Write('PK' + String.fromCharCode(5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
zipFile.Close();
var source = strLogPath.path + '\\Logs';
// Test if is null folder
if (source == null) {
// throw new TypeError();
}
// copy all the source files into the zipfile
shell.NameSpace(zipFilename).CopyHere(source);
WScript.Sleep(2000);
// delete directory
fs_obj.DeleteFolder(strLogPath.path + '\\Logs');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment