function ZipFile()
{
if ( arguments.length == 0 ) {
return;
}
this.open.apply(this, arguments);
};
(function()
{
var fso = new ActiveXObject('Scripting.FileSystemObject');
var shellApp = new ActiveXObject("Shell.Application");
ZipFile.prototype.open = function(name, create, overwrite)
{
if ( create ) {
var zipFile = fso.CreateTextFile(name, !! overwrite, 0);
zipFile.Write('PK\05\06' + new Array(19).join('\0')); // 18 zeros
zipFile.Close();
}
this.name = fso.GetFile(name).Path;
this.file = shellApp.NameSpace(this.name);
};
ZipFile.prototype.flush = function(timeout)
{
timeout = Math.max(Number(timeout) || 0, 100);
WScript.Sleep(timeout);
};
ZipFile.prototype.forEach = function(func)
{
if ( typeof func != 'function' ) {
throw new TypeError();
}
var arcfile = this.file;
var items = arcfile.Items();
for (var e = new Enumerator(items); ! e.atEnd(); e.moveNext()) {
var folderItem = e.item();
func(folderItem, arcfile);
}
};
ZipFile.prototype.forInput = function(input, func)
{
if ( typeof func != 'function' ) {
throw new TypeError();
}
var arcfile = this.file;
if ( typeof input == 'string' ) {
input = [input];
}
for (var i = 0; i < input.length; i++) {
var p = input[i];
if ( ! p ) {
continue;
}
var folderItem = null;
if ( fso.FileExists(p) ) {
folderItem = fso.GetFile(p);
} else if ( fso.FolderExists(p) ) {
folderItem = fso.GetFolder(p);
}
func(folderItem, arcfile);
}
};
})();
// Zippen
var projFileName = projektname;
var zipfile = new ZipFile();
zipfile.open("C:\\cnc\\USER\\" + projFileName + ".zip", true, true); //TempZip erstellen in:
zipfile.forInput(
[
"C:\\cnc\\USER\\projdata"
// hier können weitere Folder rein
],
function(folderItem, arcfile){
arcfile.CopyHere(folderItem.Path, 0);
setTimeout(function(){
// Projekt Suffix von .zip in .cm5 umbenennen
var renFile = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
pathToMyDocuments = shell.SpecialFolders('MyDocuments');
// Erzeuge .CM5-File und in "BENUTZERNAME\Dokumente\CM5Projects" verschieben
//alert(corrContentPath)
renFile.CopyFile("C:\\cnc\\USER\\" + projFileName + ".zip", corrContentPath, 1); // 1=overwrite
renFile.DeleteFile("C:\\cnc\\USER\\" + projFileName + ".zip", true); //Nach verschieben tempZip löschen
renFile = null;
},4000);
});
}