Make Your Own
Zip Command
by John Lansdale
Compiling an Open Source Project from Source - In Windows.
While working on a project in Windows XP that usually runs
in Linux I discovered something missing. The command for compressing
files, “zip” is available in almost all Linux distro’s
but not Windows XP. I could comment it out, etc. but making
temporary patches in semi-live code just for testing isn’t
the best idea. The test isn’t exact and it may be forgotten.
I needed a real zip.exe (command) with the same Linux options.
Figure 1. The PHP program expecting a zip command
system("zip -j $filepath.zip $dir/* >/dev/null");
// run the zip command
rename("$filepath.zip", "$html_root/$filename.zip");
// rename the .zip file
Yes Windows XP has SentTo Compressed folders, and yes my system
has WinZip. I even have 7-zip and bzip2.exe, but nothing named "zip”,
that creates “.zip” files and has the same Linux
options. The evaluation version of WinZip won’t even
run from the command line. Winzip32.exe pops up a window. I
needed the real thing.
After some search I found the Open Source project I needed,
Zip For Windows at http://gnuwin32.sourceforge.net/packages/zip.htm.
It had the zip binary (.exe) I needed but being somewhat unsure
of its exact compatibility with the Linux version assumed in
my PHP program I decided to download and compile the whole
source file. Now maybe this was just an excuse because I could
have just downloaded and tried the binary. But then what if,
like so many of the other zip-alike programs on my system it
didn’t work. Oh, and I could do review the source looking
for any virus/spyware -- very important. Besides, having run
gcc (the standard c++ compiler) in Linux enough times. I was
curious if it worked in Windows.
The answer is yes. A little different from Linux but one can
compile open source c++ projects in windows without paying
any money. It is fairly fast and easy to do. No C++ knowledge
is needed. Here’s how. .
Download the Zip for Windows source files at: http://gnuwin32.sourceforge.net/packages/zip.htm
and unpack. Note the folder.
Next get a C compiler and where better than Microsoft? Free
Visual Studio Express; Visual Studio C++ can be downloaded
at http://www.microsoft.com/express/download/ . Yes this is
Microsoft giving away something that not long ago cost over
$400. And they also have C#, Vb.Net, Asp.net and Sql Server
2005, enough to do just about any project you want. I think
they were pushed into it by IBM’s incredibly good, also
free GUI source editor Eclipse and a plethora of other good
programming environments. You have to register after 30 days
to get the software key. I’ve done it for C# and Microsoft
doesn’t seem to be too intrusive (i.e. no junk mail.)
Setup was easy.
Hardest part is finding the C++ project in your unpacked zip
project. Its name is zip.vcproj and mine was way down in C:\gun32\src\zip\2.31\zip-2.31\win32\vc6.
Start C++ and browse to open it. It works. No errors or anything.
You just take Build->Build Solution and it works. Output
zip.exe (binary) goes to . C:\gnu32\src\zip\2.31\zip-2.31\win32\vc6\zip___Win32_Debug.
The project is still in debug mode. If you take Build->Configuration
Manager and change zip from debug to release the output goes
to …\ zip___Win32_Release. You could also change the
target folder in Project->Zip Properties.
Figure 2. zip project o[en in Visual Studio Express, Visual
Studio C++
Copy the exe to some location in the system path (or add one)
and try. Mine worked perfectly, even using the –j option
(to only zip top level files) correctly.
Figure 3. Test it out. Compare to man zip (Google it or do it
in Linux). Pretty close match on options. For me the –j
option works as intended.
C:\>zip
Copyright (C) 1990-2005 Info-ZIP
Type 'zip "-L"' for software license.
Zip 2.31 (March 8th 2005). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
The default action is to add or replace zipfile entries from list, which
can include the special name - to compress standard input.
If zipfile and list are omitted, zip compresses stdin to stdout. |
-f freshen: only changed files
-d delete
entries in zipfile
-r recurse into directories
-0 store
only
-1 compress faster
-q quiet
operation
-c add one-line comments -@ read
names from stdin
-x exclude the following names
-F fix
zipfile (-FF try harder)
-A adjust self-extracting
exe
-T test zipfile integrity |
-u update: only changed
or new files
-m move
into zipfile (delete files)
-j junk (don't record) directory names
-l convert LF to
CR LF (-ll CR LF to LF
-9 compress better
-v verbose operation/print version
info
-z add zipfile comment -o make zipfile as old
as latest entry
-i include only the following names
-D do not add directory
entries
-J junk zipfile prefix (unzipsfx)
-X eXclude eXtra file
attributes
|
-! use privileges (if granted) to obtain
all aspects of WinNT security |
-R PKZIP recursion (see manual)
-$ include
volume label
-e encrypt |
-S include system and hidden files
-n don't
compress these suffixes |
C:\>zip -j mytest.zip zopesite/*
adding: Password.txt (208 bytes security) (stored 0%)
adding: start.bat (208 bytes security) (deflated 10%)
adding: z2.pyc (208 bytes security) (deflated 57%)
adding: Zope.cgi (208 bytes security) (deflated 43%)
adding: zpasswd.pyc (208 bytes security) (deflated 55%) |
Now we’re ready to make some changes, compile and change
other Open Source projects. Which, just as soon as I finish this
PHP project and a couple more and I learn Java in our Open Source
SIG and I get a little more time to study C++ and you finish
up that Java, Cold Fusion, shell script, C#, VBA and COBOL job
we’ll have to get together and work on something.
John Lansdale, CDP, MCP
|