DIRCOMP.BAT - a Directory/Application Compressor

This batch uses the PKZIP25 program to compress a directory and its subdirectories into a zip file then creates a custom batch that extracts the files, runs a specified application via the Windows start command, updates the zip file if anything changed, then removes the uncompressed files. It is similar in concept to the DIR2BAT program except creates two files rather than all in a single huge (and nonfunctional if you accidently edit it) batch file. Although the prior single file approach has the advantage of being just one file and running from the desktop without a visual show of temp files, this is more practical and allows use of normal zip file managers, uses less temp space and can automatically update the zip file if anything changes. Just add the new files to the whatever.tmp directory while open, or in the case of saved web pages using Netscape edit in place.

For best results place the dircomp.bat file in a path directory, c:\windows will do if you don't already have a directory for path things. To compress an application, web page or other directory of files with a file inside that can be launched (does something when double-clicked), go to a dos prompt and change to the directory containing the files.

If the files are in say d:\page (for example) and when you run msdos prompt it says c:\> then enter:

To create a mypage.bat and mypage.zip files that extract and run say index.html, enter:

This creates mypage.bat and mypage.zip in the root directory of the current drive. To create the files in another directory specify the destination directory name after the file to run:

Make sure that the first parameter for the output name is plain with no extension, and the second parameter, the run file, actually exists. The run file can be any windows program or associated file or valid command. Use quotes around the run file parameter if it's a long filename or a multi-word command.

Here it is... DIRCOMP.BAT

@echo off
if not .%2==. goto begin
echo.
echo DIRCOMP.BAT (c)1998 Terry Newton
echo Requires PKZIP25.EXE
echo.
echo This batch compresses all files in current directory and
echo below into a zip file and creates a batch file that unzips
echo the files into a temp directory, runs the specified file,
echo then removes the files after updating the zip if any changes.
echo.
echo Usage: DIRCOMP filebase runfile [destdir]
echo Filebase should not have extension or path, 
echo creates filebase.zip and filebase.bat in destdir
echo If destdir isn't specified, creates files in root
echo If naming a root dir, specify like d: (not d:\)
echo.
echo Example: DIRCOMP webpage index.htm d:\myfiles
goto end
:begin
if not exist %3\nul md %3
if exist %3\nul goto compile
echo cannot create destdir
goto end
:compile
echo Compiling...
pkzip25>nul -add -dir %3\%1.zip
echo> %3\%1.bat @echo off
echo>>%3\%1.bat md %1.tmp
echo>>%3\%1.bat if not exist %1.tmp\nul goto end
echo>>%3\%1.bat pkzip25 -ext -dir -ove %1.zip %1.tmp
echo>>%3\%1.bat dir /-p /s %1.tmp %% "%% | find /v "dir(s)" > %% "%% %1.dir
echo>>%3\%1.bat cls
echo>>%3\%1.bat echo.
echo>>%3\%1.bat echo Launching %2
echo>>%3\%1.bat echo Waiting for application to end
echo>>%3\%1.bat cd %1.tmp
echo>>%3\%1.bat start /w %2
echo>>%3\%1.bat cd ..
echo>>%3\%1.bat dir /-p /s %1.tmp %% "%% | find /v "dir(s)" > %% "%% %1.cmp
echo>>%3\%1.bat fc %1.cmp %1.dir %% "%% | %% "%% find "FC: no diff"
echo>>%3\%1.bat if not errorlevel 1 goto cleanup
echo>>%3\%1.bat cd %1.tmp
echo>>%3\%1.bat pkzip25 -add=update -dir ..\%1.zip
echo>>%3\%1.bat cd ..
echo>>%3\%1.bat :cleanup
echo>>%3\%1.bat deltree /y %1.tmp
echo>>%3\%1.bat del %1.cmp
echo>>%3\%1.bat del %1.dir
echo>>%3\%1.bat cls
echo>>%3\%1.bat :end
:end


Output batch modifications...

Long filenames seem to be taking over so this batch is set up to use PKZIP25.EXE, the 32 bit indows-compatible version of the popular PKZIP archive utility. However, for things that do not contain long filenames, the standard pkzip and pkunzip are faster, and often produces smaller archives. It is more convenient to leave the dircomp.bat file alone and make the modifications to the loader that it produces. The changes are trivial, here's an example of a loader modified to use pkunzip and pkzip:

@echo off
md cmachine.tmp
if not exist cmachine.tmp\nul goto end
::pkzip25 -ext -dir -ove cmachine.zip cmachine.tmp
pkunzip -d cmachine.zip cmachine.tmp
dir /-p /s cmachine.tmp % "% | find /v "dir(s)" > % "% cmachine.dir
cls
echo.
echo Launching cmachine.htm
echo Waiting for application to end
cd cmachine.tmp
start /w cmachine.htm
cd ..
dir /-p /s cmachine.tmp % "% | find /v "dir(s)" > % "% cmachine.cmp
fc cmachine.cmp cmachine.dir % "% | % "% find "FC: no diff"
if not errorlevel 1 goto cleanup
cd cmachine.tmp
::pkzip25 -add=update -dir ..\cmachine.zip
pkzip -u -rp ..\cmachine.zip *.*
cd ..
:cleanup
deltree /y cmachine.tmp
del cmachine.cmp
del cmachine.dir
cls
:end

The filesize is not always smaller with PKZIP, and there's the added risk of long filenames being added and being squashed to 8.3 so it might be more reasonable to change only the first pkzip25 occurence and get the speed but leave the pkzip25 update line alone in case Windows ultimately intrudes... easier to uncomment a line than have to fix an archive. Remember :: is like a batch comment, makes it easy to leave the original lines in.

By the way, the % "% strings are leftovers from the method used to echo batch with redirection from another batch. Dos ignores any variable that begins with a space so they evaluate to nothing. It is impossible to echo a line that contains > < or | to another file unless the characters are enclosed in quotes (after evars are expanded), so %% "%% strings surround the redirection characters, leaving % "% in the output but I really want those redirection characters to be able to check the directory for changes. Delete them if you want.

The self-updating feature isn't necessary for files that shouldn't change, for safety you can trim all that stuff out leaving just...

@echo off
md cmachine.tmp
if not exist cmachine.tmp\nul goto end
pkzip25 -ext -dir -ove cmachine.zip cmachine.tmp
cls
echo.
echo Launching cmachine.htm
echo Waiting for application to end
cd cmachine.tmp
start /w cmachine.htm
cd ..
deltree /y cmachine.tmp
cls
:end

Other loader modifications might be convenient, for example, setting a different current directory or customizing the text that is displayed. The update switches I'm using do not remove deleted files from the archive, I prefer it that way. I'm not aware of a switch that would sync the contents, one solution is to simply delete the zip then recreate, but if for some reason the computer went down while it was happening you'd lose the file. Safer would be to rename the original zip then delete it after the zipping is done, or use a zip archive manager to remove extra files from the archive. If the launch file is a dos program, remove the start /w from in front of the program name. If it is a batch file, add call in front of the filename. When running dos programs make sure the program doesn't change the current directory. To get rid of the dos window that pops up while a compressed directory is running, right click the batch or shortcut that launches it and select properties and pick the option to run minimized.

Updated December 22 1998