[an error occurred while processing this directive]
Mike guymal.com
My mic to the world...


Home Back to Tech Corner

Here are the commands I tend to use the most in my batch files.  Note that Change & Answer are both 3rd party apps.  See makebld.bat for an example using all these commands!

:<LABEL> CLS ECHO SET
IF GOTO <LABEL> PAUSE TYPE
DELTREE SYS FORMAT DEL
  CHOICE ATTRIB REBOOT
CHANGE ANSWER

 

:<label> The colon ":" is used to denote a "label".  Labels are used in conjunction with  the "GOTO" command.
CLS CLS will clear the screen.  This is handy when switching between menus.
ECHO Displays messages, or turns command-echoing on or off.

ECHO [ON | OFF]
ECHO [message]

Type ECHO without parameters to display the current echo setting.
SET Sets an environment variable *** Very useful !! ie: set imageloc=win95
Now, whenever the batch file sees %imageloc% , it will replace that with win95 .  
ie: set imageloc=win95\100full
Yes, you can even include a back-slash!  This is great for determining where to copy a file based on a menu choice.

Official /? result:

Displays, sets, or removes Windows environment variables.

SET [variable=[string]]

variable Specifies the environment-variable name.
string Specifies a series of characters to assign to the variable.

Type SET without parameters to display the current environment variables.

IF Performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command

NOT Specifies that Windows should carry out the command only
if the condition is false.
ERRORLEVEL number Specifies a true condition if the last program run returned
an exit code equal to or greater than the number specified.
command Specifies the command to carry out if the condition is
met.
string1==string2 Specifies a true condition if the specified text strings
match.
EXIST filename Specifies a true condition if the specified filename
exists.
 GOTO Directs Windows to a labelled line in a batch program.

GOTO <label>
<label> Specifies a text string used in the batch program as a label.
You type a label on a line by itself, beginning with a colon.
PAUSE Suspends processing of a batch program and displays the message:
Press any key to continue....
TYPE Displays the contents of text files.
TYPE [drive:][path]filename
DELTREE Deletes a directory and all the subdirectories and files in it.

To delete one or more files and directories:
DELTREE [/Y] [drive:]path [[drive:]path[...]]

/Y Suppresses prompting to confirm you want to delete the subdirectory.
[drive:]path Specifies the name of the directory you want to delete.

Note: Use DELTREE cautiously. Every file and subdirectory within the specified directory will be deleted.
SYS Copies MS-DOS system files and command interpreter to a disk you specify.

SYS [drive1:][path] drive2:

[drive1:][path] Specifies the location of the system files.
drive2: Specifies the drive the files are to be copied to.
FORMAT Formats a disk for use with MS-DOS.

FORMAT drive: [/V[:label]] [/Q] [/S] [/C] [/U]

/V[:label] Specifies the volume label.
/Q Performs a quick format.
/S Copies system files to the formatted disk.
/C Tests clusters that are currently marked "bad."
/U Forces "Unconditional" format

I've removed the older switches that aren't really needed any longer.. especially when working with hard drives :)

DEL Deletes one or more files.

DEL [drive:][path]filename [/P]
ERASE [drive:][path]filename [/P]

[drive:][path]filename Specifies the file(s) to delete. Specify multiple
files by using wildcards.
/P Prompts for confirmation before deleting each file.
CHOICE Waits for the user to choose one of a set of choices.

CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] [text]

/C[:]choices Specifies allowable keys. Default is YN
/N Do not display choices and ? at end of prompt string.
/S Treat choice keys as case sensitive.
/T[:]c,nn Default choice to c after nn seconds
text Prompt string to display

ERRORLEVEL is set to offset of key user presses in choices.
ATTRIB Displays or changes file attributes.

ATTRIB [+R | -R] [+A | -A] [+S | -S] [+H | -H] [[drive:][path]filename] [/S]

+ Sets an attribute.
- Clears an attribute.
R Read-only file attribute.
A Archive file attribute.
S System file attribute.
H Hidden file attribute.
/S Processes files in all directories in the specified path.
CHANGE

Download

Usage: change [/!IP] filespec "expr1" "expr2"

Change processes all files matching the file specification passed and
replaces all occurances of expression 1 with expression 2. The switches
perform the following:

/! - Display general program and OzWoz information.
/I - Ignore case of expressions.
/P - Prompt before changing.
ANSWER

Download

 There are no switches to this one, including /?  - This small file waits for the user to type something and hit enter.  It then sets %answer% to whatever the user typed.  IE:

Echo Enter your name:

\utils\answer :    <--- that colon will be displayed on a blank line as a prompt for the user to enter a name

:  username   <--- Now, %answer% = "username" (without the quotes of course)

REBOOT

Download

Reboots a pc while in dos mode





2001 Guy Malachi, All Rights Reserved