BatZap is a script language for modifying batch files and other configuration files in text format. Because it's a script language, it is able to make precise changes and conditionally add or change lines within a file based on a number of conditionals.
BatZap can also be used as a smart batch file switch program. It can read system information and conditionally set environment variables and dos errorlevel codes used by batch files. This allow batch file to branch based on conditions controlled by BatZap.
Usage: BATZAP <Script File>Written in MarxMenu. Comes free with the Network Survival Kit.
BatZap AUTO.BZ ;the BZ extension is assumed
Example:Commands are interpreted left to right, so you may have to use parens in order to control the order of execution.
ReadFile 'C:\AUTOEXEC.BAT' SubSt 'C:\DOS' 'C:\NWDOS' if Find 'PATH=' if not (ThisLine contains 'C:\NWDOS') ThisLine = ThisLine + 'C:\NWDOS;' endif endif WriteFile
ReadFile 'C:\CONFIG.SYS' if not Find 'NOVSYNC.SYS' AddLine 'Device=NOVSYNC.SYS 05' Writeln 'NovSync Device Driver Added to CONFIG.SYS' WriteFile endif
;- Update Driver if Necessary
if 'C:\NOVSYNC.SYS' IsOlderThan 'N:\NOVSYNC.SYS' Writeln 'Updating NovSync Device Driver from Server' Execute 'COPY N:\NOVSYNC.SYS C:\NOVSYNC.SYS' endif
Example:There are several other examples at the end of this file which you may find useful.
3 + 4 * 2 ; returns 14 3 + (4 * 2) ; returns 11 if InGroup(Accounting) and (DayOfWeek = 'FRI')
BATZAP VOCABULARY: ------------------
BatZap defines 26 variables, the letters A to Z. These variables can be used to store numbers (4-byte LONG integers), strings (up to 255 characters), or boolean values (True/False).
Adds two values.
Writeln 'A' + 'B' ; String concatenation. Use ' or " for strings. Writeln 3 + 5
Subtracts two values.
Writeln 5 - 3
Multiplies two values.
Writeln 6 * 3
Divides two values.
Writeln 6 / 3
Compares two values and returns true if they are equal.
if 2 + 2 = 4
Compares two values and returns true if they are not equal.
if 2 + 2 <> 5
Compares two values and returns true if the first value is greater than the second value.
if 'D' > 'C'
Compares two values and returns true if the first value is less than the second value.
if 'C' < 'D'
Compares two values and returns true if the first value is greater than or equal to the second value.
if 'D' >= 'C'
Compares two values and returns true if the first value is less than or equal to the second value.
Example:=== ( )
if 'C' <= 'D'
Parens begin and end logical grouping for interpretation.
Example:=== AddLine (String)
if ('A' < 'B') and (9 > (5 + 3))
AddLine adds a line to the buffer just after the line number that CurrentLine is set to. After a ReadFile, CurrentLine is set to the last line in the file. If you set CurrentLine to 0, AddLine will add the line to the beginning of the buffer.
CurrentLine = 1 if not (ThisLine StartsWith '@ECHO') CurrentLine = 0 AddLine '@Echo Off' endif
And returns the logical And of two values.
Example:=== Char (Number) : String
if InGroup 'EveryOne' and InGroup 'Accounting'
Char returns the ascii character of the number passed.
Example:=== ConsoleOperator : Boolean
Write Char(10) ;writes a line feed
ConsoleOperator returns True if the user is a Novell console operator.
Example:=== ChDir (Directory)
if ConsoleOperator ErrorLevel = 1 endif
ChDir changes drives and directories.
Contains returns True if the string on the left contains the string on the right.
Example:=== CPU : Number
if ThisLine contains 'NWDOS'
CPU returns the class of CPU chip you are running.
Example:=== CurrentDirectory : String
if CPU >= 3
Returns the current directory.
Example:=== CurrentLine : Number
Writeln CurrentDirectory ;returns 'F:\NSK'
CurrentLine returns the line number for which other commands that use CurrentLine act on. You can also set CurrentLine.
Example:=== DayOfWeek : String
CurrentLine = CurrentLine - 1 ;go to previous line
DayOfWeek returns the first three letters of the day of the week.
Example:=== DelBlock (Start,End)
if DayOfWeek = 'TUE'
DelBlock deletes all the lines from Start to End (inclusive).
Example:=== DelChar (String,Position,Count) : String
DelBlock 5 9 ; deletes lines 5, 6, 7, 8, and 9
DelChar deletes Count characters from String at Position and returns the result.
Example:=== DelLine (Line)
Writeln DelChar('12345',3,2) ;returns '125'
DelLine deletes the specified line. If Line isn't specified, the CurrentLine is assumed.
Example:=== DeleteFile (Name)
DeleteFile deletes a file. It can also delete a read-only file.
Example:=== DelSection (Name)
DelSection deletes a group of lines beginning with a line that contains the string ('SECTION: ' + Name) and ending with the line that contains the string ('END SECTION: ' + Name). If you put sections in your file that are commented like in the following example, then DelSection will allow you to take the whole section out in one command.
Example:=== Display : String
Your file contains:
REM ---------[ Section: Network ]-----------
LoadHi LSL LoadHi NE2000 LoadHi IPXODI LoadHi NETX
REM -------[ End Section: Network ]---------
DelSection 'NETWORK' ;removes the entire section
Display returns the type of video card. Types returned are HERC, CGA, EGA, VGA.
Example:=== DosVersion : Number
if Display = 'VGA'
DosVersion returns a number that is 100 times the major dos version plus the minor dos version. Note that this is the version returned by the API interface which doesn't always match what the VER command returns.
Writeln DosVersion ; under dos 3.3 will return 330
=== EndLine : Number
EndLine returns the line number for which other commands that use EndLine act on. You can also set EndLine. EndLine is used with StartLine to specify a block of lines to be used by block commands line SubSt and DelBlock.
StartLine = 4 EndLine = 6 SubSt 'OLD' 'NEW'
=== ErrorLevel : Number
When ErrorLevel is set to a value between 0 and 255, BatZap returns that errorlevel to a batch file that is calling it.
Example:A batch file that tests if you are in a Novell group might look like this:
ErrorLevel = 1
BatZap GrpTest if ErrorLevel 1 goto Yes ... ... :YesThe GRPTEST.BZ file might look like this:
if InGroup 'ACCOUNTING' ErrorLevel = 1 endif=== Execute (CommandLine)
Execute will execute a DOS command line. This can be used to create directories and copy files.
Example:=== ExistFile (FileName) : Boolean
if not ExistDir 'C:\NET' Execute 'MD C:\NET' Execute 'XCOPY Z:\LOCALDVR\*.* C:\NET /S' endif
ExistFile returns True if the file exists.
Example:=== ExistDir (Directory) : Boolean
if ExistFile 'C:\QEMM.386'
ExistDir returns True if the Directory exists. It can also be used to test if a drive exists or a disk is missing from a floppy drive.
if ExistDir 'C:\DOS' if ExistDir 'A:'
Exit returns to DOS and exits the BatZap program. (Optional)
=== ExitCode : Number
Returns the DOS error level code from the last execute command. For ExitCode to work properly, you need to use the EXE or COM extension with the Execute command.
Example:=== False : Boolean
Execute 'INMEM.EXE BREQUEST' if ExitCode > 0
Returns the value False.
Example:=== FileAttribute : Number
if A = False ;same as: if not A
FileAttribute is a variable where BatZap stores the attributes of the file read. (Hidden, System, and Read Only) These attributes are used to set the attributes when the file is written. By setting this value you can change the resulting attributes.
Example:The file attribute values are as follows:
FileAttribute = 1 (read only) WriteFile
Read Only 1 Hidden 2 System 4 Execute-Only 8 Subdirectory 16 Archive 32 Shareable 128(You can add these together to create whatever combination you need.)
=== FileLog (FileName,String)
FileLog will write the line String to the end of file FileName. This feature can be used to keep a log of updates made for later inspection.
Example:=== Find (String) : Boolean
FileLog('Z:AUTO.LOG',UserName + ' Updated!')
Find searches the buffer for String and returns True if found. It also sets CurrentLine to the line the string was found on.
Example:Find works within the range of StartLine and Endline which is initially the entire file. The FindRange command can be used to find a section of a file and it sets StartLine and EndLine. After FindRange, the Find command searches only that section of the file. To get Find to search the whole file after a FindRange, use the WholeFile command.
if Find 'PATH=' if not (ThisLine contains 'C:\NWDOS') ThisLine = ThisLine + 'C:\NWDOS;' endif endif
Find can be used to find a line that contains a string, starts with a string, or exactly matches a string. See the FindMode command for details.
FindMode controls the way that a string is found. FindMode is set to the letters C,S, or M.
C = Contains the string S = Starts with the string M = Matches the stringThe default is mode C.
Example:Find modes C and S ignore leading spaces. Mode M ignored trailing spaces.
FindMode = 'S'
=== FindRange (StartString,EndString) : Boolean
FindRange is used to find a section of a file that starts with a line containing StartString and ends with a line containing EndString. This is useful for modifying NET.CFG files where you want to update one of the link drivers.
FindRange returns True if it finds StartString. It also sets CurrentLine to the line that StartString was found on and StartLine to the next line. Then it searches for EndString. If it finds it then EndLine is set to the line just before EndString. Otherwise, EndLine is set to the end of the file. Thus, if found, the StartLine and EndLine settings are set to search a block between two sections.
Example:After a FindRange command sets a range of lines for a section of the file, Find, Substitute and several other commands will affect only the section of the file defined by StartLine and EndLine.
;- find NE2000 section
if FindRange('LINK DRIVER NE2000','LINK DRIVER')
;- Search for FRAME in NE2000 section
if Find 'FRAME' ThisLine = ' FRAME Ethernet_802.2' else AddLine ' FRAME Ethernet_802.2' endif
=== FullName : String
FullName returns the Novell full name in the network bindery for the current user.
Example:=== Goto Label
SetEnv('FULLNAME=' + FullName)
Goto jumps to the line defined by Label.
Example:=== If (Condition)
Goto Hello ... Label Hello Writeln 'Hello World'
If allows for conditionals in BatZap. If the condition is met, all lines between If and Endif are executed. Otherwise, lines between Else and Endif are executed.
Example:=== InGroup (Group) : Boolean
if Condition ... ... if Condition ... ... endif ... ... elseif Condition ... ... elseif Condition ... ... else ... ... endif
InGroup returns True if user is in the Novell group.
Example:=== InMem (tsr) : Boolean
if InGroup 'EveryOne'
InMem returns true if the TSR specified is in memory.
Example:=== InsChar (Ins,String,Position) : String
if InMem 'BREQUEST'
InsChar inserts string Ins into String at Position and returns the resulting string.
Writeln InsChar('ABC','12345',3) ;returns '12ABC345'
IsOlderThan is used to compare the dates of files, or the date of a file to a time string. A file that doesn't exist is older than one that does exits. This can be used to test to see if a local file need to be updated from a newer network file.
if 'C:\NET.CFG' IsOlderThan 'P:\NET.CFG' if 'C:\CONFIG.SYS' IsOlderThan '09-01-94'
=== LastLine : Number
LastLine returns the line number of the last line in the buffer.
Example:=== Left (String,Count) : String
Left returns the left Count characters of String.
Example:=== LeftOfEqual (String) : String
Writeln Left('ABCD',2) ;returns 'AB'
LeftOfEqual returns that part of a string that is left of the equal sign. The string includes the = itself.
Example:=== Length (String) : Number
Writeln LeftOfEqual('PATH=C:\DOS') ;returns PATH=
Length returns the length of a string.
Example:=== LoggedIn : Boolean
Writeln Length 'ABC' ;returns 3
Returns True if user is logged into a Novell network.
=== LowerCase (String) : String
LowerCase returns the LowerCase of a string.
Example:=== MathChip : Boolean
ThisLine = LowerCase ThisLine
MathChip returns true if you have a math coprocessor.
Example:=== Mid (String,Position,Count) : String
Mid returns a substring of String at Position for length Count.
Example:=== MkDir (Name)
Writeln Mid('12345',3,2) ;returns '34'
MkDir creates a directory.
Example:=== Month : String
Month returns the first three letters of the Month.
Example:=== NameOfFile : String
if Month = 'AUG'
NameOfFile returns the name of the file that was read with ReadFile.
Not returns the logical Not of a value.
if Not InGroup 'EveryOne'
Normally BatZap makes a BAK file when it overwrites an existing file. If you execute NoBak then the BAK file isn't created.
=== Now : Number
Now returns the current time.
Or returns the logical Or of two values.
Example:=== Ord (String) : Number
if InGroup 'EveryOne' or InGroup 'Accounting'
Ord returns the ascii value of a character.
Example:=== Param (Number) : String
Write Ord('A') ;returns 65
Param returns the command line parameter passed when BatZap is executed. It allows you to pass command line parameters to the script logic. Param(2) is the name of the script file itself.
Example:=== Pos (Search,String) : Number
You run: BatZap MOD.BZ C:\CONFIG.SYS ReadFile Param(3) ;reads the file name you passed on command line
Pos returns the position of string Search in String. If String doesn't contain Search, Pos returns a 0.
Example:=== ReadEnv (Environment String) : String
Writeln Pos('BCD','ABCDE') ;returns 2
ReadEnv returns the value of an environment variable.
Example:=== ReadFile (FileName)
if ReadEnv 'ENHANCED' = 'Y'
ReadFile reads a text file into the BatZap buffer for modification. The size of the file is limited to the amount of memory available, but generally is up around 250k. If the FileName is omitted, the command line parameter after the script file name is assumed to be the file name to read.
Example:If a second ReadFile is executed before a WriteFile, the new file is inserted into the buffer at location CurrentLine. This allows you to merge files into one file. A WriteFile clears the buffer and allows you to start modifying a new file.
When the first file is read, CurrentLine is set to the last line of the file, and the StartLine and EndLine pointers are set to the beginning and end of the file. FileName and FileAttribute are set.
If a second file is merged, the CurrentLine pointer is set to the end of the new lines and the StartLine and EndLine pointers are set to enclose the new data. FileName and FileAttribute are not set.
BatZap supports having multiple ReadFile and WriteFile commands in the same script. This allows you to write one script that modifies several files.
Reboots the computer. Sometimes after changing the CONFIG.SYS and AUTOEXEC.BAT files you want to reboot the computer to make the changes take effect.
=== RenameFile (OldName,NewName)
RenameFile renames file OldName to NewName.
Example:=== Replace (Old,New)
RenameFile 'OLD' 'NEW'
Replace will find all occurrences of the string Old and replace it with the string New on the current line only. Use Subst to do multiple lines.
Example:=== Right (String,Count) : String
Replace 'F:\PUBLIC\' 'P:\'
Right returns the right Count characters of String.
Example:=== RightOfEqual (String) : String
Writeln Right('ABCD',2) ;returns 'CD'
RightOfEqual returns that part of a string that is right of the equal sign. The string does not include the = itself.
Example:=== RmDir (Name)
Writeln RightOfEqual('PATH=C:\DOS') ;returns C:\DOS
RmDir removes a directory.
Example:=== SecurityEqual (User or Group) : Boolean
SecurityEqual returns True if the user is security equivelent to user. Novell networks only.
Example:=== Server : String
if SecurityEqual('SUPERVISOR') SetEnv('CMD=SUPER.BAT') endif
Server returns the name of the default file server.
Example:=== SetEnv (String)
if Server = 'MARX'
SetEnv sets an environment variable to a value. This can be used with conditionals to control the execution of a batch file running BatZap.
Example:A batch file calling this might look like this:
if InGroup 'PAYROLL' SetEnv('CMD=PAYROLL.BAT') else SetEnv('CMD=USER.BAT') endif
BatZap FORK.BZ %CMD%In the above example, the batch file will jump to one of two batch files depending on BatZap setting an environment variable.
=== SetIndent (Number)
SetIndent sets the number of spaces a section of the file is indented. The section is defined by StartLine and EndLine. After a FindRange, SetIndent can be used to indent all the lines in a section to the same number of spaces making the result file visually attractive and consistent.
Example:=== ShellLoaded : Boolean
if FindRange('LINK DRIVER NE2000','LINK DRIVER') SetIndent 3
ShellLoaded returns True if the VLM shell or NETX shel is loaded.
=== StartLine : Number
StartLine returns the line number for which other commands that use StartLine act on. You can also set StartLine. StartLine is used with EndLine to specify a block of lines to be used by block commands line SubSt and DelBlock.
StartLine = 4 EndLine = 6 SubSt 'OLD' 'NEW'
StartsWith returns true if the string on the left starts with the string on the right.
Example:=== Station : String
if ThisLine StartsWith 'REM'
Station returns the workstation address on a Novell network.
Example:=== Str (Number) : String
if Station = '250:33333' ; The format is Network Number:Node
Str returns the string of a given number.
Example:=== Subst (Old,New)
Writeln Str(2 + 4) ;returns '6'
Subst will find all occurrences of the string Old and replace it with the string New. The range is from StartLine to EndLine which is normally set to include the whole buffer. Use the Replace command if you want to do the CurrentLine only.
Example:=== Supervisor : Boolean
Substitute 'F:\PUBLIC\' 'P:\'
Returns True if user is equivelent to the Novell network supervisor.
=== ThisLine : String
ThisLine returns the contents of the line that CurrentLine is set to. It can also be used to set the contents of the CurrentLine.
Example:=== TimeOf (File or String) : Number
CurrentLine = 1 if ThisLine StartsWith 'ECHO' ThisLine = '@' + ThisLine endif
TimeOf returns the time of a file or a string. The time is a number that represents the number of seconds since 01-01-80.
Example:=== Trim (String) : String
if TimeOf 'C:\AUTOEXEC.BAT' > TimeOf '09-01-94 2:45pm' Exit endif
if TimeOf 'C:\QEMM386.SYS' < TimeOf 'P:\QEMM\QEMM386.SYS' Execute 'XCOPY P:\QEMM\*.SYS C:\' endif
if TimeOf 'C:\AUTOEXEC.BAT' < (Now - (3600 * 24 * 7) ;- Over a week old endif
Trim returns a string with Spaces abd Tabs removed from the begining and end of the string.
Example:=== TrimTrail (String) : String
ThisLine = Trim ThisLine
TrimTrail returns a string with Spaces abd Tabs removed from the end.
Example:=== True : Boolean
ThisLine = Trim ThisLine
Returns the value True.
Example:=== TrueName (String) : String Returns the TrueName (Network Name) of a file or Directory.
if A = True ;same as: if A
Example:=== UpperCase (String) : String
SetEnv('SAVEDIR=' + TrueName 'Z:\')
UpperCase returns the UpperCase of a string.
Example:=== UserName : String
if UpperCase ReadEnv 'ENHANCED' = 'Y'
UserName returns the Novell login name of the user.
Example:=== Value (String) : Number
if UserName = 'Marc'
Value turns String into a Number.
Example:=== VlmLoaded : Boolean
Writeln Value('23') ;returns number 23
VlmLoaded returns True if the VLM shell is loaded and False for NETX.
=== VinesLoaded : Boolean
VlmLoaded returns True if the Banyan Vines shell is loaded.
While is a control conditional like If and Endif. While the condition is true, the lines between while and endwhile are executed.
While Condition ... ... While Condition ... ... EndWhile ... ... EndWhile
WholeFile sets FirstLine and LastLine to the first and last lines of the buffer.
=== WriteFile (FileName)
WriteFile writes the BatZap buffer to a text file and clears the buffer for the loading of another file. A single BatZap script can modify many text files. If the FileName is omitted the name of the file read is assumed. If the file written is the same name as the file read, and the original file was read only, then the modified file will also be read only.
Example:=== Write (String)
Write writes a string on the screen without a CR.
Example:=== Writeln (String)
Writeln writes a string on the screen with a CR.
Or returns the logical Xor of two values.
Example:COMMON EXAMPLE SCRIPTS: -----------------------
if InGroup 'EveryOne' xor InGroup 'Accounting'
Here are some examples of common modification scripts that you might need to use.
Suppose we are changing our windows directory from C:\WIN to C:\WINDOWS. Here is an example of how it might be done.
ReadFile 'C:\AUTOEXEC.BAT' if Find 'PATH=' Replace 'C:\WIN;' 'C:\WINDOWS;' WriteFile endifNow we are updating our CONFIG.SYS files for the new version of QEMM that we just upgraded to. Here's how it's done.
ReadFile 'C:\CONFIG.SYS' if Find 'QEMM386.SYS'BATZAP WITH OTHER PROGRAMS --------------------------
;- Add the RAM switch if it isn't there
if pos('RAM',ThisLine) = 0 ThisLine = ThisLine + ' RAM' endif
A = CurrentLine - 1 if not ( A StartsWith 'DOS-UP.SYS' )
;- Add DosUp and DosData lines before and after Qemm line
CurrentLine = A AddLine 'device=dos-up.sys' CurrentLine = CurrentLine + 1 AddLine 'device=dosdata.sys'
;- Copy the files down to the local hard drive
Execute 'COPY P:\QEMM\*.SYS C:\' endif
BatZap can be combined with other Computer Tyme programs to increase it's power. For example, if you want to update all batch files that start with Echo Off to @Echo Off:
WHEREIS *.BAT|DOLIST BATZAP ECHO.BZ @L
Whereis scans the entire drive and pipes the list into DoList. DoList executes BatZap for every line in the pipe substituting the filename for @L in the command line.
ABOUT INI FILES ---------------
Yes, BatZap can do INI files, but I have a program called IniTyme and it is written specifically for INI files. If you want to do INI files, get IniTyme.
NEED MORE POWER? ----------------
You like BatZap, but you need more power. BatZap doesn't have all the features you want? No Problem. The next step is to upgrade to MarxMenu, the language that BatZap it written in. MarxMenu is the world's most powerful script language and can give you the power you need to do complex processing, or greater speed. Call us or download MarxMenu from our web site and take a look at it.
- Utilities Documentation Files.
MarxMenu TOC - MarxMenu Table of Contents.
MarxMenu Index - MarxMenu Index.
Download - Access our Download Library.
Yep! It runs with Netware 4 - Yep, Uh Huh - Sure Does.
Screens - Gallery of Screen Shots.