File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ * Original technique from http://naterice.com/zip-and-unzip-files-using-the-windows-shell-and-vbscript/
3
+ */
4
+
1
5
function create_zip ( dst )
2
6
{
3
7
var header = "\x50\x4b\x05\x06" +
4
8
"\x00\x00\x00\x00\x00\x00\x00\x00\x00" +
5
9
"\x00\x00\x00\x00\x00\x00\x00\x00\x00" ;
6
10
11
+ /*
12
+ * Trick to write a binary file regardless of the system locale
13
+ */
7
14
var outw = new ActiveXObject ( "ADODB.Stream" ) ;
8
15
outw . Type = 2 ;
9
16
outw . Open ( ) ;
@@ -38,13 +45,23 @@ function zip(src, dst)
38
45
{
39
46
var shell = new ActiveXObject ( 'Shell.Application' ) ;
40
47
var fso = new ActiveXObject ( 'Scripting.FileSystemObject' ) ;
48
+
49
+ /*
50
+ * Normalize paths, required by the shell commands
51
+ */
41
52
src = fso . GetAbsolutePathName ( src ) ;
42
53
dst = fso . GetAbsolutePathName ( dst ) ;
43
54
55
+ /*
56
+ * Create an empty zip file if necessary
57
+ */
44
58
if ( ! fso . FileExists ( dst ) ) {
45
59
create_zip ( dst ) ;
46
60
}
47
61
62
+ /*
63
+ * Check for duplicates
64
+ */
48
65
var zipfile = shell . Namespace ( dst ) ;
49
66
var files = zipfile . items ( ) ;
50
67
var count = files . Count ;
@@ -55,6 +72,11 @@ function zip(src, dst)
55
72
}
56
73
57
74
zipfile . CopyHere ( src ) ;
75
+
76
+ /*
77
+ * Wait for completion, but data can be stale on network shares, so we
78
+ * abort after 5 seconds.
79
+ */
58
80
var max_tries = 50 ;
59
81
while ( count == zipfile . items ( ) . Count ) {
60
82
WScript . Sleep ( 100 ) ;
You can’t perform that action at this time.
0 commit comments