Directory to Batch Revisited

PKWare now has a new v2.5 version of PKZIP that is compatible with the old pkzip/pkunzip but supports long filenames, making my original directory-batch compressor viable as-is. Despite the "short filenames only" warning, if used with the pkzip/pkunzip from PK250DOS.EXE it works fine with long filenames.

I find that compressing pages/apps to a single self-contained batch is more convenient than using a separate batch to unzip the archive, mainly because the resulting batch can be launched from within another zip file, and in general it is easier to keep up with one file than two. The originally posted DIR2BAT required 2 different versions of pkzip to accomplish this and not mangle filenames, because the "new" pkzip25 couldn't tolerate extracting an archive appended to a batch. Thankfully the new pkzip/pkunzip-compatible version 2.5 doesn't mind, making this old batch useful again.

:: DIR2BAT1 (c)1998 Terry Newton
:: This batch "compiles" directories with subdirectories
:: into compressed self-extracting batch files that when
:: run temporarily decompress and run the specified file
:: using the windows start command. Decompresses to current
:: drive. This version for short filenames only!
:: Usage: DIR2BAT1 batfile runfile filemask [filemask] ...
:: For example: DIR2BAT1 webpage.bat index.htm *.*
:: Batfile should end in .bat
@echo off
if .%3==. echo DIR2BAT1 batfile runfile filemask [filemask] ...
if .%3==. goto end
echo Compiling...
md \dir2bat$
:: zip up target files...
pkzip>nul \dir2bat$\ %3 %4 %5 %6 %7 %8 %9 -rp
pkzip>nul \dir2bat$\ \dir2bat$\
:: create a loader...
echo> \dir2bat$\dir2bat.t1 @echo off
echo>>\dir2bat$\dir2bat.t1 echo   Unzipping files
echo>>\dir2bat$\dir2bat.t1 md \dir2bat$
echo>>\dir2bat$\dir2bat.t1 pkunzip %%0 \dir2bat$%% "%%>nul%% "%%
echo>>\dir2bat$\dir2bat.t1 pkunzip \dir2bat$\ \dir2bat$ -d%% "%%>nul%% "%%
echo>>\dir2bat$\dir2bat.t1 cd \dir2bat$
echo>>\dir2bat$\dir2bat.t1 echo   Waiting for application to end
echo>>\dir2bat$\dir2bat.t1 start /w %2
echo>>\dir2bat$\dir2bat.t1 cd \
echo>>\dir2bat$\dir2bat.t1 echo   Removing files
echo>>\dir2bat$\dir2bat.t1 deltree /y \dir2bat$%% "%%>nul%% "%%
echo>>\dir2bat$\dir2bat.t1 cls
:: add an EOF char...
copy \dir2bat$\dir2bat.t1 \dir2bat$\dir2bat.t2 /a>nul
:: append loader and zip and copy to target in current...
copy/b \dir2bat$\dir2bat.t2+\dir2bat$\ %1>nul
:: clean up...
deltree /y \dir2bat$>nul