Question : Create ZIP from Batch file w/o third party utility

Anyone have a way to create a ZIP file from a DOS batch file without the use of the third party utility?

My only other alternative is to maintain an empty ZIP file that's copied/renamed as I need it and move files into that.

I'd prefer not to have to install any third party utilities on the dozens of servers I would like to run this from.

VBSCript would be acceptable as well but prefer a DOS batch file as it's easier for others to edit/maintain.

Answer : Create ZIP from Batch file w/o third party utility

While I understand why you do not want to install a program to do this, would you be okay with a 3rd party command line executable which can be stored on the server where the batch file is run from, and referenced there?

(If So Try 7-Zip)

 7Zip's command line files can run from the Share you call the batch file from and not cause any real network issues because the file would be executed on the local client side.

 Though if you prefer not to run the file remotely, but that is not necessary for this file because it is very small.

 You can DL 7Zip here: http://www.7-zip.org/download.html

(If Not Then See Below)

 I found this VB Script which purports to do exactly what you're looking for, if it must be done without any 3rd party files of any sort, then I would try using this VB Script I have attached.


 NOTE: I did not write this Script, I found it here: http://www.visualbasicscript.com/m53086.aspx
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
' VB Script to ZIP a File:

 Function fZip(sSourceFolder,sTargetZIPFile)
 'This function will add all of the files in a source folder to a ZIP file
 'using Windows' native folder ZIP capability.
 'Returns an integer 0 if everything went ok.
  Dim oShellApp, oFSO, iErr, sErrSource, sErrDescription
  Set oShellApp = CreateObject("Shell.Application")
  Set oFSO = CreateObject("Scripting.FileSystemObject")
   'The source folder needs to have a \ on the End
   If Right(sSourceFolder,1) <> "\" Then sSourceFolder = sSourceFolder & "\"
  On Error Resume Next 
    'If a target ZIP exists already, delete it
    If oFSO.FileExists(sTargetZIPFile) Then oFSO.DeleteFile sTargetZIPFile,True 
   iErr = Err.Number
  On Error GoTo 0
   If iErr <> 0 Then   
    fZip = iErr
    Exit Function
   End If
  On Error Resume Next
   'Write the fileheader for a blank zipfile.
   oFSO.OpenTextFile(sTargetZIPFile, 2, True).Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
   iErr = Err.Number
  On Error GoTo 0
   If iErr <> 0 Then   
    fZip = iErr
    Exit Function
   End If
  On Error Resume Next 
   'Start copying files into the zip from the source folder.
   oShellApp.NameSpace(sTargetZIPFile).CopyHere oShellApp.NameSpace(sSourceFolder).Items
   iErr = Err.Number
  On Error GoTo 0
   If iErr <> 0 Then   
    fZip = iErr
    Exit Function
   End If
    'Because the copying occurs in a separate process, the script will just continue.  Run a DO...LOOP to prevent the function
    'from exiting until the file is finished zipping.
    Do Until oShellApp.NameSpace(sTargetZIPFile).Items.Count = oShellApp.NameSpace(sSourceFolder).Items.Count
     WScript.Sleep 500
    Loop
  fZip = 0
 End Function
Random Solutions  
 
programming4us programming4us