title: Copy folder contents to a created .zip file: 'file not found or no read permissions'
body: <p>I'm trying to create a .zip file from an existing folder using JScript and it seems that my copyHere function is not copying to the .zip folder. Instead I get a popup box titled 'Compressed (zipped) Folder Error' with the message 'file not found or no read permissions' even though I have read/write privileges on the file according to the value of my file.attributes property (32).</p>
  
  <p>Here is the script I'm using:</p>
  
  <pre class="lang-js prettyprint-override"><code>//Get commman line arguments
  var objArgs = WScript.Arguments;
  var zipPath = objArgs(0);
  var sourcePath = objArgs(1);
  
  //Create empty ZIP file and open for adding
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  
  var file = fso.CreateTextFile(zipPath, true);
  // Create twenty-two byte "fingerprint" for .zip
  file.write("PK");
  file.write(String.fromCharCode(5));
  file.write(String.fromCharCode(6));
  file.write('\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0');
  
  var objShell = new ActiveXObject("shell.application");
  var zipFolder = new Object;
  
  zipFolder = objShell.NameSpace(zipPath);
  
  sourceItems = objShell.NameSpace(sourcePath).items();    
  
  if (zipFolder != null)
  {
      zipFolder.CopyHere(sourceItems);  
      WScript.Sleep(1000);      
  }
  </code></pre>
  
  <p>Now the CopyHere function works for copying the contents of the sourcePath to a normal folder but when I try to create a .zip file and copy the contents to that, nothing happens. Any ideas on why copyHere is not copying the contents of the sourcePath to the .zip?</p>
  
  <p><strong>An Example</strong> for calling this script would be:</p>
  
  <p><code>cscript win-zip.js C:\desired\zip\file.zip C:\path\to\source\folder</code></p>
  
  <p>And the <strong>desired outcome</strong> would be that file.zip was created and now contains the contents of the source folder. Could this be a problem with permissions? What might cause this behavior?</p>
  
  <hr>
  
  <p><strong>Side Note</strong>, using a vbScript and the same commands I can successfully create and populate a .zip, so why doesn't it work using jscript!</p>
  
  <pre class="lang-vbs prettyprint-override"><code>Set objArgs = WScript.Arguments
  ZipFile = objArgs(0)
  SourceFolder = objArgs(1)
  
  ' Create empty ZIP file and open for adding
  CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" &amp; Chr(5) &amp; Chr(6) &amp; String(18, vbNullChar)
  Set zip = CreateObject("Shell.Application").NameSpace(ZipFile)
  
  ' Get items in source folder
  Set sourceItems = CreateObject("Shell.Application").NameSpace(SourceFolder).Items
  
  ' Add all files/directories to the .zip file
  zip.CopyHere(sourceItems)
  WScript.Sleep 1000 'Wait for items to be copied
  </code></pre>
  
  <hr>
  
  <p>Any <em>helpful</em> comments are greatly appreciated, thanks!</p>