views:

47

answers:

4

I am trying to write a script that I can give to user to have it automatically zip certain files of theirs 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? I have been looking for quite a bit but I am struggling.

Thanks.

+1  A: 

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.

Shubh
If 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
That could be an alternative too. It all depends on what the situation demands..
Shubh
A: 

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.

dj_segfault
ftp -s:scriptfile hostname ;)
Anders
A: 

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.

JYelton
+1  A: 

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.

Anders