BATZAP - Batch File Script Language

Prev Next Home Home Table Of Contents Index

BATZAP - Batch File Script Language

Download:
BATZAP.ZIP

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>

Example:
BatZap AUTO.BZ ;the BZ extension is assumed

Written in MarxMenu. Comes free with the Network Survival Kit.


Example:
Modify AUTOEXEC.BAT:

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

Example:
Modify CONFIG.SYS:

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

Commands are interpreted left to right, so you may have to use parens in order to control the order of execution.


Example:
3 + 4 * 2 ; returns 14 3 + (4 * 2) ; returns 11 if InGroup(Accounting) and (DayOfWeek = 'FRI')

There are several other examples at the end of this file which you may find useful.

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.


Example:
Writeln 'A' + 'B' ; String concatenation. Use ' or " for strings. Writeln 3 + 5

=== -

Subtracts two values.


Example:
Writeln 5 - 3

=== *

Multiplies two values.


Example:
Writeln 6 * 3

=== /

Divides two values.


Example:
Writeln 6 / 3

=== =

Compares two values and returns true if they are equal.


Example:
if 2 + 2 = 4

=== <>

Compares two values and returns true if they are not equal.


Example:
if 2 + 2 <> 5

=== >

Compares two values and returns true if the first value is greater than the second value.


Example:
if 'D' > 'C'

=== <

Compares two values and returns true if the first value is less than the second value.


Example:
if 'C' < 'D'

=== >=

Compares two values and returns true if the first value is greater than or equal to the second value.


Example:
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:
if ('A' < 'B') and (9 > (5 + 3))

=== AddLine (String)

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.


Example:
CurrentLine = 1 if not (ThisLine StartsWith '@ECHO') CurrentLine = 0 AddLine '@Echo Off' endif

=== And

And returns the logical And of two values.


Example:
if InGroup 'EveryOne' and InGroup 'Accounting'

=== Char (Number) : String

Char returns the ascii character of the number passed.


Example:
Write Char(10) ;writes a line feed

=== ConsoleOperator : Boolean

ConsoleOperator returns True if the user is a Novell console operator.


Example:
if ConsoleOperator ErrorLevel = 1 endif

=== ChDir (Directory)

ChDir changes drives and directories.


Example:
ChDir 'F:\PUBLIC'

=== Contains

Contains returns True if the string on the left contains the string on the right.


Example:
if ThisLine contains 'NWDOS'

=== CPU : Number

CPU returns the class of CPU chip you are running.


Example:
if CPU >= 3

=== CurrentDirectory : String

Returns the current directory.


Example:
Writeln CurrentDirectory ;returns 'F:\NSK'

=== CurrentLine : Number

CurrentLine returns the line number for which other commands that use CurrentLine act on. You can also set CurrentLine.


Example:
CurrentLine = CurrentLine - 1 ;go to previous line

=== DayOfWeek : String

DayOfWeek returns the first three letters of the day of the week.


Example:
if DayOfWeek = 'TUE'

=== DelBlock (Start,End)

DelBlock deletes all the lines from Start to End (inclusive).


Example:
DelBlock 5 9 ; deletes lines 5, 6, 7, 8, and 9

=== DelChar (String,Position,Count) : String

DelChar deletes Count characters from String at Position and returns the result.


Example:
Writeln DelChar('12345',3,2) ;returns '125'

=== DelLine (Line)

DelLine deletes the specified line. If Line isn't specified, the CurrentLine is assumed.


Example:
DelLine 10

=== DeleteFile (Name)

DeleteFile deletes a file. It can also delete a read-only file.


Example:
DeleteFile 'AUTOEXEC.BAK'

=== 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:

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 : String

Display returns the type of video card. Types returned are HERC, CGA, EGA, VGA.


Example:
if Display = 'VGA'

=== DosVersion : Number

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.


Example:
Writeln DosVersion ; under dos 3.3 will return 330

=== Else

See IF.

=== ElseIf

See IF.

=== EndIf

See IF.

=== 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.


Example:
StartLine = 4 EndLine = 6 SubSt 'OLD' 'NEW'

=== EndWhile

See While.

=== 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:
ErrorLevel = 1

A batch file that tests if you are in a Novell group might look like this:


 BatZap GrpTest
 if ErrorLevel 1 goto Yes
 ...
 ...
 :Yes

The 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:
if not ExistDir 'C:\NET' Execute 'MD C:\NET' Execute 'XCOPY Z:\LOCALDVR\*.* C:\NET /S' endif

=== ExistFile (FileName) : Boolean

ExistFile returns True if the file exists.


Example:
if ExistFile 'C:\QEMM.386'

=== ExistDir (Directory) : Boolean

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.


Example:
if ExistDir 'C:\DOS' if ExistDir 'A:'

=== Exit

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:
Execute 'INMEM.EXE BREQUEST' if ExitCode > 0

=== False : Boolean

Returns the value False.


Example:
if A = False ;same as: if not A

=== FileAttribute : Number

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:
FileAttribute = 1 (read only) WriteFile

The file attribute values are as follows:

   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:
FileLog('Z:AUTO.LOG',UserName + ' Updated!')

=== Find (String) : Boolean

Find searches the buffer for String and returns True if found. It also sets CurrentLine to the line the string was found on.


Example:
if Find 'PATH=' if not (ThisLine contains 'C:\NWDOS') ThisLine = ThisLine + 'C:\NWDOS;' endif endif

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.

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

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 string

The default is mode C.


Example:
FindMode = 'S'

Find modes C and S ignore leading spaces. Mode M ignored trailing spaces.

=== 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:

ReadFile 'NET.CFG'

;- 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

endif

WriteFile

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.

=== FullName : String

FullName returns the Novell full name in the network bindery for the current user.


Example:
SetEnv('FULLNAME=' + FullName)

=== Goto Label

Goto jumps to the line defined by Label.


Example:
Goto Hello ... Label Hello Writeln 'Hello World'

=== If (Condition)

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:
if Condition ... ... if Condition ... ... endif ... ... elseif Condition ... ... elseif Condition ... ... else ... ... endif

=== InGroup (Group) : Boolean

InGroup returns True if user is in the Novell group.


Example:
if InGroup 'EveryOne'

=== InMem (tsr) : Boolean

InMem returns true if the TSR specified is in memory.


Example:
if InMem 'BREQUEST'

=== InsChar (Ins,String,Position) : String

InsChar inserts string Ins into String at Position and returns the resulting string.


Example:
Writeln InsChar('ABC','12345',3) ;returns '12ABC345'

=== IsOlderThan

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.


Example:
if 'C:\NET.CFG' IsOlderThan 'P:\NET.CFG' if 'C:\CONFIG.SYS' IsOlderThan '09-01-94'

=== Label

See Goto

=== LastLine : Number

LastLine returns the line number of the last line in the buffer.


Example:
Writeln LastLine

=== Left (String,Count) : String

Left returns the left Count characters of String.


Example:
Writeln Left('ABCD',2) ;returns 'AB'

=== LeftOfEqual (String) : String

LeftOfEqual returns that part of a string that is left of the equal sign. The string includes the = itself.


Example:
Writeln LeftOfEqual('PATH=C:\DOS') ;returns PATH=

=== Length (String) : Number

Length returns the length of a string.


Example:
Writeln Length 'ABC' ;returns 3

=== LoggedIn : Boolean

Returns True if user is logged into a Novell network.

=== LowerCase (String) : String

LowerCase returns the LowerCase of a string.


Example:
ThisLine = LowerCase ThisLine

=== MathChip : Boolean

MathChip returns true if you have a math coprocessor.


Example:
if MathChip

=== Mid (String,Position,Count) : String

Mid returns a substring of String at Position for length Count.


Example:
Writeln Mid('12345',3,2) ;returns '34'

=== MkDir (Name)

MkDir creates a directory.


Example:
MkDir 'C:\NET'

=== Month : String

Month returns the first three letters of the Month.


Example:
if Month = 'AUG'

=== NameOfFile : String

NameOfFile returns the name of the file that was read with ReadFile.

=== Not

Not returns the logical Not of a value.


Example:
if Not InGroup 'EveryOne'

=== NoBak

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

Or returns the logical Or of two values.


Example:
if InGroup 'EveryOne' or InGroup 'Accounting'

=== Ord (String) : Number

Ord returns the ascii value of a character.


Example:
Write Ord('A') ;returns 65

=== Param (Number) : String

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:
You run: BatZap MOD.BZ C:\CONFIG.SYS ReadFile Param(3) ;reads the file name you passed on command line

=== Pos (Search,String) : Number

Pos returns the position of string Search in String. If String doesn't contain Search, Pos returns a 0.


Example:
Writeln Pos('BCD','ABCDE') ;returns 2

=== ReadEnv (Environment String) : String

ReadEnv returns the value of an environment variable.


Example:
if ReadEnv 'ENHANCED' = 'Y'

=== ReadFile (FileName)

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:
ReadFile 'C:\CONFIG.SYS'

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.

=== Reboot

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:
RenameFile 'OLD' 'NEW'

=== Replace (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:
Replace 'F:\PUBLIC\' 'P:\'

=== Right (String,Count) : String

Right returns the right Count characters of String.


Example:
Writeln Right('ABCD',2) ;returns 'CD'

=== RightOfEqual (String) : String

RightOfEqual returns that part of a string that is right of the equal sign. The string does not include the = itself.


Example:
Writeln RightOfEqual('PATH=C:\DOS') ;returns C:\DOS

=== RmDir (Name)

RmDir removes a directory.


Example:
RmDir 'C:\NET'

=== SecurityEqual (User or Group) : Boolean

SecurityEqual returns True if the user is security equivelent to user. Novell networks only.


Example:
if SecurityEqual('SUPERVISOR') SetEnv('CMD=SUPER.BAT') endif

=== Server : String

Server returns the name of the default file server.


Example:
if Server = 'MARX'

=== SetEnv (String)

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:
if InGroup 'PAYROLL' SetEnv('CMD=PAYROLL.BAT') else SetEnv('CMD=USER.BAT') endif

A batch file calling this might look like this:


   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:
if FindRange('LINK DRIVER NE2000','LINK DRIVER') SetIndent 3

=== ShellLoaded : Boolean

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.


Example:
StartLine = 4 EndLine = 6 SubSt 'OLD' 'NEW'

=== StartsWith

StartsWith returns true if the string on the left starts with the string on the right.


Example:
if ThisLine StartsWith 'REM'

=== Station : String

Station returns the workstation address on a Novell network.


Example:
if Station = '250:33333' ; The format is Network Number:Node

=== Str (Number) : String

Str returns the string of a given number.


Example:
Writeln Str(2 + 4) ;returns '6'

=== Subst (Old,New)

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:
Substitute 'F:\PUBLIC\' 'P:\'

=== Supervisor : Boolean

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:
CurrentLine = 1 if ThisLine StartsWith 'ECHO' ThisLine = '@' + ThisLine endif

=== TimeOf (File or String) : Number

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:
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 (String) : String

Trim returns a string with Spaces abd Tabs removed from the begining and end of the string.


Example:
ThisLine = Trim ThisLine

=== TrimTrail (String) : String

TrimTrail returns a string with Spaces abd Tabs removed from the end.


Example:
ThisLine = Trim ThisLine

=== True : Boolean

Returns the value True.


Example:
if A = True ;same as: if A

=== TrueName (String) : String Returns the TrueName (Network Name) of a file or Directory.


Example:
SetEnv('SAVEDIR=' + TrueName 'Z:\')

=== UpperCase (String) : String

UpperCase returns the UpperCase of a string.


Example:
if UpperCase ReadEnv 'ENHANCED' = 'Y'

=== UserName : String

UserName returns the Novell login name of the user.


Example:
if UserName = 'Marc'

=== Value (String) : Number

Value turns String into a Number.


Example:
Writeln Value('23') ;returns number 23

=== VlmLoaded : Boolean

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

While is a control conditional like If and Endif. While the condition is true, the lines between while and endwhile are executed.


Example:
While Condition ... ... While Condition ... ... EndWhile ... ... EndWhile

=== WholeFile

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:
WriteFile 'C:\CONFIG.SYS'

=== 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.


Example:

=== Xor

Or returns the logical Xor of two values.


Example:
if InGroup 'EveryOne' xor InGroup 'Accounting'

COMMON EXAMPLE SCRIPTS: -----------------------

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
 endif

Now 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'

;- 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

WriteFile endif

BATZAP WITH OTHER PROGRAMS --------------------------

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.

Prev Next Home Home Table Of Contents Index

Sponsors
Shopping
Forum
Forum
email
EMail
Index
Index
Home
Home