I am trying to write a script that I can give to user to have it automatically zip certain files and then load them onto an ftp site. Anyone know where I could find information on writing a batch file for auto-zipping files using only what is available to a user running Windows?
-
2possible duplicate of [Can Windows' built-in ZIP compression be scripted?](http://stackoverflow.com/questions/30211/can-windows-built-in-zip-compression-be-scripted) – Mark O'Connor Aug 28 '12 at 21:48
-
[here](http://stackoverflow.com/questions/28043589) you can find an native compressing utilities in windows – npocmaka Feb 04 '15 at 11:09
6 Answers
It is possible to work with zip files by using the compressed folder (COM) support and Windows Scripting Host. You would start by creating the Shell.Application object. The FolderItem object has methods like CopyHere etc that will allow you to manipulate a zip file like a folder. See this page for zip and unzip sample code.

- 97,548
- 12
- 110
- 164
Since (AFAIK) Windows doesn't come with a program that can zip up files from the command line. For that matter, it doesn't come with a scriptable ftp program, either (there is an ftp command, but it's interactive).
Your best bet is to write a program in some compiled language with access to libraries for zipping files and ftp.

- 11,957
- 4
- 29
- 37
Multiple forums (I can't find an official Microsoft answer) suggest that the zip functionality built into Windows is provided by dlls for which there is no command line argument. For example:
The unzipping is a function of zipfldr.dll, so would use regsvr32.exe to invoke it, and as far as I know there are no arguements you can add to it for unzipping via batch file.
-- from technologyquestions.com
I would recommend a third party program, of which there are many (which you could provide along with a script): 7zip, winzip, pkzip, etc.
Also you might want to look into VBScript or WSH as alternatives to batch files.

- 35,664
- 27
- 132
- 191
Windows has its own zip command. You can put the code below in a backup.bat file and run.
@echo off
:: variables
set drive=E:\backup
set backupcmd=xcopy /s /c /d /e /h /i /r /y
echo ### Backing up My Documents...
%backupcmd% "e:\Repositories" "%drive%\SVNrepository\Repositories"
e:
cd "%drive%\SVNrepository"
zip -r -S -T -$ -m Repositories.zip Repositories
set filename="..\Repository_bak_%date:~0,4%%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%.zip"
move .\*.zip %filename%
cd E:\backup\
echo Backup Complete!
rem @pause

- 7
- 1
-
7I'm using Windows 8 and "zip" isn't a valid command in my command prompt. – seagull Apr 17 '15 at 12:36
By csgnrg@yahoo.it
If you want convert a single file into a single zip file you can use gzip.exe
Let oProcess.Cwd = oOutput.PATH
oProcess.SetUsePosition
oProcess.SetUseSize 0, 0
oProcess.ExeCmd "gzip.exe gzip -f -q -c -9 " & oSource.Source & " > " & oOutput.Source, True
If oProcess.Error Then
Let ErrorMsg = oProcess.ErrorMsg
Exit Sub
End If
A better alternative to batch file would be to use a JAR and use Java's java.util.zip package to zip the files. Or how about distributing the bat file with a JAR. People could execute the BAT file and it in turn could run the JAR.

- 1,363
- 2
- 13
- 23
-
8If using external tools is the way to go, why the hell would you pick java? There are plenty of small command line apps that can create zip files – Anders May 22 '10 at 12:58
-
1