title: Zipping files from different folders preserving the directory structure
body: <p>I've hacked together some pretty interesting code to zip multiple files and folders.</p>
  
  <p>The script will take a list of arguments (files &amp; folders) and zips them to a zip with the date/time as the name.</p>
  
  <p>So I need some code that is executed when the argument is a file.  The code should add the directory structure of the file to the zip file.</p>
  
  <pre><code>'=================== THE SCRIPT =====================================
  
  'Get command-line arguments.
  Set objArgs = WScript.Arguments
  Set objShell = CreateObject("Shell.Application")
  '
  'C:\DateYYYY-MM-DD_TimeHH-MM-SS.zip
  ZipFile = "C:\DateYYYY-MM-DD_TimeHH-MM-SS.zip"
  'Create empty ZIP file.
  CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile, True).Write "PK" &amp; Chr(5) &amp; Chr(6) &amp; String(18, vbNullChar)
  Set zip = objShell.NameSpace(ZipFile)
  '
  for i = 0 To objArgs.Count-1  
      On Error Resume Next
      IF fnFileExists( objArgs(i) ) OR (NOT fnFolderIsEmpty( objArgs(i) )) THEN 
          'WScript.Echo "Copying - " &amp; objArgs(i)
          IF fnFileExists( objArgs(i) ) THEN
            '??? Code/Function/CopyHere[option] to create a directory structure in zip and copy objArgs(i) file into it
          End If
          zip.CopyHere( objArgs(i) )
      Else 
          WScript.Echo "Empty or !Exist - " &amp; objArgs(i)
      End If
      Do 
          wScript.Sleep 200 
      Loop Until objShell.NameSpace(zip).Items.Count &gt;= i 
  Next
  WScript.Echo "THE END"
  </code></pre>
  
  <p>The <code>fnFileExists()</code> function returns <code>TRUE</code> only if the file exists (<code>FALSE</code> if folder or file doesn't exist).</p>
  
  <p>The <code>fnFolderIsEmpty()</code> function returns <code>TRUE</code> if folder is empty or doesn't exist.</p>
  
  <p>Given a call like this:</p>
  
  <pre><code>"wscript zip.vbs "c:\Folder1\" "c:\Folder2\Sub2-1\" "c:\Windows\System32\TestFile0.txt"
  </code></pre>
  
  <p>Where folders are like this:</p>
  
  <pre><code>\Folder1\
  └──TestFile1.txt
  └──TestFile2.txt
  \Folder2\
  └──\Sub2-1\
      └──TestFile3.txt
      └──TestFile4.txt
  \Windows\
  └──\System32\
      └──TestFile0.txt
  └──\Sub3-2\
      └──TestFoo.txt
  </code></pre>
  
  <p>I get a zip file with a structure like this:</p>
  
  <pre><code>\Folder1\
  └──TestFile1.txt
  └──TestFile2.txt
  \Sub2-1\
  └──TestFile3.txt
  └──TestFile4.txt
  \TestFile0.txt
  </code></pre>
  
  <p>This is what I'd LIKE it to look like:</p>
  
  <pre><code>\Folder1\
  └──TestFile1.txt
  └──TestFile2.txt
  \Folder2\
  └──\Sub2-1\
      └──TestFile3.txt
      └──TestFile4.txt
  \Windows\
  └──\System32\
      └──TestFile0.txt
  </code></pre>
  
  <p>I did find the following, but I don't know how/if Java translates to VBScript:</p>
  
  <p><a href="https://stackoverflow.com/questions/1399126/java-util-zip-recreating-directory-structure">java.util.zip - Recreating directory structure</a><br>
  -AND-<br>
  <a href="https://stackoverflow.com/questions/4946175/zipping-files-preserving-the-directory-structure">Zipping files preserving the directory structure</a></p>