; This file can be executed AS IS, despite what looks like un-executable ; text in it. Reason: each comment line begins with 2 NUL characters (ascii ; decimal value of 0). 4DOS 3.0 will not read any batch file line that ; starts with a NUL. In fact, this way of making comments is MUCH, MUCH ; faster for 4DOS 3.0 than any other method. With comments done this way, ; the delay caused by their presence should be almost imperceptible ; Disclaimer: it works for me, using MS-DOS 3.3 and 4DOS 3.0. ; When you execute the batch file, if you begin seeing a lot of ; "UNKNOWN COMMAND" messages from 4DOS right away, terminate ; IMMEDIATELY with CTRL-C or CTRL-BREAK. That would mean, I ; suppose, that the NULs don't work with *every* DOS version. Sigh ... SETLOCAL goto START ; The what-to-do-in-case-of-fatal-error labels are all toward the ; top of the batch file. But begin reading, below, at the :START label. :QUIT echo  ^ CANCEL ; the :QUIT routine is called several times the same way. Might as ; well have it as a single routine gotten to via GOTO, rather than ; repeat it several times in the batch file. :ENV_ERR cls ^ screen 12 0 Fatal error! RONSET.EXE returned errorlevel 255, screen 13 0 possibly indicating that you're out of environment space. screen 15 0 Must terminate. Sorry ... ^ CANCEL ; This is the sole kind of error trapping in the file for environ- ; ment space errors. So watch it. :PK_ERR cls ^ beep 900 1 ^ screen 6 0 ERROR! screen 8 0 ^ echo %prog% returned an error (exit) code of  %?  during: screen 10 0  %OP%  screen 12 0 Must cancel. Killing all files in the temporary directory, screen 13 0 and quitting. ^ screen 22 0 CTTY NUL echo y|del e:\____()$-\*.* ^ rd e:\____()$- CTTY CON CANCEL ; The "del *.*" instruction uses a pipe command: pipe a "y" to ; "del *.*" - this automatically gives a "yes" answer to the ; "Are you sure? (y/n)" question DOS will ask when you try to ; delete an entire directory in this way. ; The "%?" in the error message is the internal 4DOS 3.0 variable ; which contains the last exit code returned. Very handy! :FILE_ERR cls ^ screen 10 0 TEXT Something went wrong. Either I could not create the temporary directory, or else I was not able to copy the source file into it. I will remove the temporary directory if it was created, and terminate. ENDTEXT if isdir e:\____()$- rd e:\____()$- CANCEL ; Uses the 4DOS command SCREEN for an initial placement of the cursor ; following "CLS," then uses the 4DOS TEXT command. :START IFF "%1" == "" THEN echo Forget it. Can't do nuttin' without a source file name! cancel ENDIFF ; The above is self-explanatory, I hope. Except: the  part is an ; ANSI.SYS instruction which says: "put the screen message on the SAME ; screen line where the command itself was issued (i.e., from the DOS ; prompt) IFF "%@ext[%1]" ne "" THEN IFF "%@ext[%1]" ne "zip" THEN echo has to be a .ZIP file! ^ cancel ENDIFF ENDIFF ; In the above instructions, first there is a test to see if the file's ; extension is blank. This uses the 4DOS 3.0 variable function %@EXT[]. ; If you didn't add an extension to the file name, then %@EXT returns ; NOTHING. In that case the rest of the test is skipped. ; If you DID supply an extension, then the line: iff "%@ext[%1]" ne "" ; evaluates as true, and the next test is performed - is the extension ; NOT ".ZIP"? If it isn't, give an error message and quit. ; The first test uses the 4DOS "not equal to" function to determine if ; "%@ext[%1]" is (n)ot (e)qual to "" IFF not exist %1.zip THEN IFF not exist %1 THEN echo ZIP file "%1" doesn't exist here on %_cwd%. ^ cancel ELSE set fi=%1 ^ goto CHEKWILD ENDIFF echo ZIP file "%1.ZIP" doesn't exist here on %_cwd%.^ cancel ELSE set fi=%1.zip ^ goto CHEKWILD ENDIFF ; This set of instructions checks for the existence of the file name ; typed on the command line, whether or not you put an extension in its ; name. ; The main loop here is "if %1.ZIP doesn't exist." In other words, it ; tacks the string ".ZIP" onto the end of "%1." If you gave a name like ; TEST.ZIP as your file name, then this produces: TEST.ZIP.ZIP and of ; course that file doesn't exist, even if TEST.ZIP does. ; If the first test is false - "%1.ZIP" *DOES* exist - then the batch ; file is told to jump immediately to the next label - no more testing ; for the existence of files. ; If the first test is TRUE - "%1.ZIP" does *NOT* exist - then process ; the next test: What about "%1" alone? If "%1," without any ".ZIP" ; tacked on, does exist, then jump to the next label. ; In all of the preceding, if "%1.ZIP" is found then a variable FI ; is created containing "%1.ZIP". If on the other hand "%1" alone is ; found, then the FI variable is created, containing "%1" alone. This ; is to avoid any further confusion when it comes time (in a moment) ; to check the read-only attribute of the file. This way you have a ; known quantity that all parts of the batch file can use: a file name ; with ".ZIP" on the end. :CHEKWILD RONSET var=if(wild(%fi%),,GOTO CHEKATTR) if errorlevel == 255 goto ENV_ERROR %var% echo Wildcards not permitted in the source file name! cancel ; This uses the excellent shareware program RONSET.EXE. There are two ; nested RONSET tests in the command, and the effect is to write an ; environment variable named VAR *if* the tests both evaluate TRUE. ; The first is actually the one nested inside the second: the WILD() ; test. Does the "%1" parameter contain a wildcard? For the purposes of ; this batch file, you don't want that. If WILD() returns a TRUE ; response, then the IF() function writes *nothing* to the variable VAR ; (not the double comma in the instruction - see the RONSET docs for more ; details about the IF() function). On the other hand, if there is no ; wildcard in "%1," then the IF() function writes the string "GOTO ; CHEKATTR" to variable VAR. ; Now, on the next line of the batch file, %var% alone appears. When the ; batch file is executed, DOS will expand the contents of VAR to whatever ; they actually are. If the RONSET instruction didn't actually write ; anything to VAR, then the line will be treated as a blank line. On the ; other hand, if RONSET wrote the string "GOTO CHEKATTR" to VAR, then ; *that* is what is expanded, and the instruction GOTO CHECKATTR is ; executed as if you had actually typed that into the batch file yourself. :CHEKATTR IFF attrib %fi% R THEN echo Can't process "%fi%" - it's read-only ^ cancel ELSE goto OLD_NAME ENDIFF ; This uses the built in ATTRIB function of 4DOS 3.0, put into an IFF ; instruction. The test evaluates as TRUE if the file is read-only. If ; so, then give an error message and quit. You don't want to try ; processing a read-only file; later on, PKZIP will just bomb out with ; an error message, since you're going to be altering the file. :OLD_NAME cls ^ FV %fi% /p ; Uses Buerg's FV program to display the source .ZIP file. Uses the /P ; switch of FV to pause the screen display every 23 lines or so. echo  ^ drawbox 0 40 18 79 0 white on black fill black drawvline 1 40 22 2 white on black ; The "echo " uses an ansi.sys command to save the current ; cursor position. ; Now use the 4DOS 3.0 DRAWBOX command to blank out an area of the screen, ; from row 0, column 40, to row 18, column 79 (in 4DOS parlance. The ; coordinates would be different if you were speaking in ansi.sys terms. ; No line attribute. Color white-on-black. That part is required by ; DRAWBOX but is not important here. But "FILL black" is - that is what ; blanks the right part of the screen. Now the file names, shown by FV, ; are still visible, but other FV-displayed data about the .ZIP file ; is not. ; DRAWVLINE draws a vertical line from row 1, column 40, and is 22 ; rows long. The line style is "2" (double line). ; From this point onward, all prompts, error messages, and status messages ; will appear on the right side of the screen. And from this point on, for ; the most part, I used ansi.sys commands for cursor positioning and ; screen colors. The sorts of commands used are: ; a;bbH "nn;nnH" positions the cursor at row "aa," column "bb." ;  save cursor position ;  restore cursor position ;  clear to end of line ;  turn on high intensity video ;  turn on inverse video ;  inverse video, and blinking ;  restore normal video echo   Rename what file in the archive?  :PROMPT_1 echo   NO WILDCARDS!  input  : %%oldname echo  ; Put a NO WILDCARDS! warning message at row 22, col. 43. Start user- ; input routine at row 6, col. 43. Prepare to write variable OLDNAME. ; As soon as something is typed and ENTER is pressed, the NO WILDCARDS ; warning is made to go away. if "%oldname%" == "" goto QUIT ; If you press ENTER alone, cancel echo  Wait a sec ... ; The above line is stricly for cosmetics' sake. set var RONSET var=if(wild(%oldname%),,GOTO OK_1) if errorlevel == 255 goto ENV_ERROR %var% echo  I said, no wildcards!  ^ delay 2 echo  ^ GOTO PROMPT_1 ; Similar kind of RONSET test - check to see if the variable OLDNAME ; contains wildcards. If so, write nothing to variable "VAR". Then the ; line reading just %var% is treated as a blank line, and the batch ; file drops through to the error message, which has a DELAY command ; (internal to 4DOS 3.0). Then you are returned to the PROMPT_1 label ; for another chance to enter a file name. ; Now you can see why the ansi "clear to end of line" commands are up ; there at the PROMPT_1 label - so that if you have to return there, ; you have a clean screen display again. ; If there is no wildcard in variable OLDNAME, then proceed to the ; next label in the batch file ( :OK_1) ; On the line where it says "I said, no wildcards!" there are ; ansi.sys commands for "restore cursor position" and then "clear ; to end of line." This is so that the nasty message will appear ; in the SAME place where the text "Wait a sec ..." just was. :OK_1 ctty nul ^ pkunzip -v %fi% %oldname% ^ ctty con ; Here use PKUNZIP to test for the existence of the file-to-be-renamed, ; within the source file ("%fi%"). Use CTTY NUL to turn off screen dis- ; play during this time, and CTTY CON to turn it back on if errorlevel == 0 goto NEW_NAME ; If PKUNZIP finds the file you want to rename, it'll return errorlevel 0. ; In that case, skip the upcoming tests and go to the next prompts IFF errorlevel gt 0 THEN echo  No file "%oldname%" in "%fi%"! INKEY  Try again? (y/n) %%yesno IFF "%yesno%" == "y" THEN echo  ^ goto PROMPT_1 ELSE goto QUIT ENDIFF ENDIFF ; If PKUNZIP doesn't find the file you want to rename, it returns a ; non-0 exit code. In that case, ask if you want to try again. This ; prompt uses the INKEY function of 4DOS. If "y" is pressed, for "yes, ; try again" then you go back to PROMPT_1, cleaning up the screen in ; the process. If not, clear the screen and quit. ; The above uses 4DOS "gt" function to determine if the errorlevel is ; (g)reater (t)han 0. :NEW_NAME echo   NO WILDCARDS!  echo  Rename it to what? input  : %%newname echo  ; Similar prompt as you saw the last time IF "%newname%" == "" goto QUIT ; Same deal - if there's a 'null response', quit. IFF "%newname%" == "%oldname%" THEN echo You gotta be kidding.^echo You can't use the same echo name for both of 'em! delay 2 ^ echo  ^ goto NEW_NAME ENDIFF ; What to do if the hapless user typed in the same name for ; the "before" *AND* the "after name." ; just in case VAR exists ... set var RONSET var=if(pos( ,%newname%),,GOTO OK_2) if errorlevel == 255 goto ENV_ERROR %var% echo   No spaces allowed!  ^ delay 2 ^ echo  ^ goto NEW_NAME ; This RONSET routine again uses "IF" but this time uses the POS() ; function to determine the position of a character within another ; character string. In this case you're testing for a space. If ; the POS() test is false (no space within the name), then write the ; text "GOTO OK_2" to the variable VAR - otherwise, write nothing. ; Same deal as before. If VAR is empty, drop immediately to the ; error message. :OK_2 set var RONSET var=if(wild(%newname%),,GOTO OK_3) if errorlevel == 255 goto ENV_ERROR %var% echo  I said, no wildcards!  ^ delay 2 echo  ^ GOTO NEW_NAME ; Another test for wildcards within the filename ("newname"). ; Similar to previous tests of that sort :OK_3 echo  Checking ... CTTY NUL ^ pkunzip -v %fi% %newname% ^ CTTY CON IFF errorlevel == 0 THEN :: echo  echo  "%newname%" is already there! inkey  Try again? (y/n) %%yesno IFF "%yesno%" == "y" THEN echo  ^ GOTO NEW_NAME ELSE goto QUIT ENDIFF ENDIFF ; if the file already exist ; Similar routine but this one causes the warning if the new file ; name *IS* found in the archive - batch file won't over-write ; an existing file. ; This is where the action starts: drawbox 0 41 18 79 0 white on black fill black ; Use DRAWBOX command again to erase the right side of the screen ; Commands are slightly different so that the existing line created ; with the prior DRAWVLINE command isn't also erased echo  Rename "%oldname%" to "%newname%"  echo   Currently in: %_cwd%  ; Additional screen displays, at top left and right of screen. ; Second one uses built-in 4DOS variable to display current working ; directory. ; Batch file now creates totally implausible temporary directory on ; drive E:, named ____()$- Change this to a hard disk drive name ; if you don't have a RAM disk (E: is my RAM disk) echo  Creating temporary subdirectory ... if not isdir e:\____()$- md e:\____()$- ; Uses internal 4DOS function "ISDIR" - same thing under COMMAND.COM ; would be: if not exist c:\____()$-\NUL md c:\____()$- ; The rest of the commands are pretty much self-explanatory. Except: ; each time PKZIP or PKUNZIP is called, a variable PROG is created so that ; if the batch file has to branch to the PK_ERR label, the right program ; name will be displayed there. ; Similarly, a variable called OP is created each time, containing ; the text of the main instruction. This is also used in the :PK_ERR ; displays (if any). ; The branching to :PK_ERR will occur any time PKZIP or PKUNZIP returns ; a non-0 exit code. ; As before, the screen displays take place entirely on the right side ; of the screen, except in the event of a fatal error. As with the :QUIT ; label, error labels referred to below are at the TOP of the batch file. ; This routine makes a complete copy of the original ZIP file before ; processing. That way, if anything goes wrong, the original will NOT ; get trashed. if not isdir e:\____()$- goto FILE_ERR ; If for some reason the temp directory could not be created, go to ; :FILE_ERR label (at top of batch file), display error message, & quit echo  Make copy of "%fi%" ... copy %fi% e:\____()$- > NUL if not exist e:\____()$-\%fi% goto FILE_ERR echo  (Copied) ; Again - go to :FILE_ERR label if for some reason the file couldn't ; be copied to the temp. directory echo  Extract "%oldname%" ... set PROG=PKUNZIP set OP=pkunzip e:\____()$-\%fi% e:\____()$- %oldname% pkunzip e:\____()$-\%fi% e:\____()$- %oldname% > NUL IF errorlevel gt 0 goto PK_ERR echo  (Extracted) echo  Renaming "%oldname%" ... ren /q e:\____()$-\%oldname% %newname% echo  (Renamed) ; The /Q switch of REN is new with 4DOS 4.0 - sets "quiet mode" ; so that the renaming isn't echoed to the screen. ; Once "%oldname%" is extracted to the temporary directory, it ; is renamed and then added back into the original .ZIP file. *THEN* ; the old name is killed from the ZIP file. set PROG=PKZIP set OP=pkzip -m e:\____()$-\%fi% e:\____()$-\%newname% echo  Moving it into "%fi%" ... pkzip -m e:\____()$-\%fi% e:\____()$-\%newname% > NUL IF errorlevel gt 0 goto PK_ERR echo  (Moved into "%fi%") set PROG=PKUNZIP set OP=pkunzip -t e:\____()$-\%fi% echo  Test altered copy of "%fi%" pkunzip -t e:\____()$-\%fi% > NUL IF errorlevel gt 0 goto PK_ERR echo  (No CRC errors) set PROG=PKZIP set OP=pkzip -d e:\____()$-\%fi% %oldname% echo  Delete "%oldname%" ... pkzip -d e:\____()$-\%fi% %oldname% > NUL IF errorlevel gt 0 goto PK_ERR echo  ("%oldname%" deleted) set PROG=PKUNZIP set OP=pkunzip -t e:\____()$-\%fi% echo  Test "%fi%" once more ... pkunzip -t e:\____()$-\%fi% > NUL IF errorlevel gt 0 goto PK_ERR echo  (No CRC errors) echo  Move "%fi%" back here ... *move e:\____()$-\%fi% > NUL echo  ("%fi%" moved back here) ; No error checking here. echo   Done.  Pausing a moment. ^ delay 3 cls ^ fv %fi% drawbox 0 40 18 79 0 white on black fill black drawvline 1 40 22 2 white on black ; Display the archive, now with the new file in it. ; Use box drawing and vertical line drawing again to split ; the screen, and prompt to see if the routine needs to be ; re-run (say, you want to run it on another file. screen 7 43 Removing temporary directory. rd e:\____()$- screen 10 43 Run same routine again, inkey  on same ZIP file? (y/n) %%yesno IFF "%yesno%" == "y" THEN cls ^ screen 13 0 ^ RENZIP.BTM %fi% ELSE goto QUIT ENDIFF