Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ch 111 Chapter 11 Advanced Batch Files. Ch 112 Overview This chapter focuses on batch file commands that allow you to:  write sophisticated batch files.

Similar presentations


Presentation on theme: "Ch 111 Chapter 11 Advanced Batch Files. Ch 112 Overview This chapter focuses on batch file commands that allow you to:  write sophisticated batch files."— Presentation transcript:

1 Ch 111 Chapter 11 Advanced Batch Files

2 Ch 112 Overview This chapter focuses on batch file commands that allow you to:  write sophisticated batch files  further refine your technique in working with the environment

3 Ch 113 Batch File Commands Batch files must …  have the file extension.BAT  be an ASCII text file  include legitimate commands

4 Ch 114 Batch File Commands Any command used at the command line can be used in a batch file.

5 Ch 115 Batch File Commands Batch files have …  a limited vocabulary ( commands )  a syntax  programming logic

6 Ch 116 A Review of the REM, PAUSE, and ECHO Commands REM command (remarks)… statements keyed in by user that tell what is the purpose of the batch file.

7 Ch 117 A Review of the REM, PAUSE, and ECHO Command PAUSE command … instructs the batch file to stop executing until the user takes some action.

8 Ch 118 A Review of the REM, PAUSE, and the ECHO Command Two ways to interrupt a batch file during execution: Ê Press + C Ë Press +

9 Ch 119 A Review of the REM, PAUSE, and the ECHO Command ECHO command … displays a command and the output of that command to the screen.

10 Ch 1110 A Review of the REM, PAUSE, and the ECHO Command When ECHO is ON:  all commands in a batch file are displayed on the screen.

11 Ch 1111 A Review of the REM, PAUSE, and the ECHO Command When ECHO is OFF …  can see the output of the command, but not the command itself.

12 Ch 1112 Advanced Features of ECHO and REM To save valuable processing time, use a double colon (::) instead of the REM command.

13 Ch 1113 Advanced Features of ECHO and REM To delete the display of even the message “ 1 file(s) copied ”, use the device NUL.

14 Ch 1114 Advanced Features of ECHO and REM Using NUL will not suppress a message such as “file not found”.

15 Ch 1115 Advanced Features of ECHO and REM To suppress all messages use the command CTTY NUL.

16 Ch 1116 Advanced Features of ECHO and REM When CTTY NUL is used, must follow with CTTY CON in order to have control of the console.

17 Ch 1117 Advanced Features of ECHO and REM There is no such thing as a blank line in batch files.

18 Ch 1118 Advanced Features of ECHO and REM To insert a blank line, key in ECHO followed by a period (ECHO.)

19 Ch 1119

20 Ch 1120 The GOTO Command GOTO command …  will branch to a new line, creating a loop  works in conjunction with a label

21 Ch 1121 The GOTO Command A loop will repeat steps until it is stopped by …  using an IF statement  breaking into the batch file with + C

22 Ch 1122 The GOTO Command A label …  is preceded by a colon (:)  can be no longer than 8 characters  is not a command

23 Ch 1123 The GOTO Command GOTO has one parameter …  GOTO label

24 Ch 1124

25 Ch 1125 The SHIFT Command The SHIFT command allows for an unlimited number of parameters on the command line.

26 Ch 1126 The SHIFT Command SHIFT command … changes the position of the replaceable parameter in a batch file.

27 Ch 1127

28 Ch 1128 The IF Command IF command … allows for conditional processing.

29 Ch 1129 The IF Command Conditional processing … compares two items to determine if they are identical, or if one is greater than the other.

30 Ch 1130 The IF Command The result of comparison testing is either a True or False value.

31 Ch 1131 The IF Command True = items are identical False = items are not identical

32 Ch 1132 The IF Command Syntax of IF command: IF

33 Ch 1133 The IF Command If a condition is True, the command will be executed. If a condition is False, the command will not be executed.

34 Ch 1134 The IF Command The IF command checks for three conditions.

35 Ch 1135 IF Command Using Strings To test whether or not one character string is exactly the same as another, use the IF command.

36 Ch 1136 IF Command Using Strings The strings to be compared are separated by two equal signs (= =).

37 Ch 1137

38 Ch 1138 Testing for NULL Values In a batch file it is sometimes possible to be caught in an endless loop.

39 Ch 1139 Testing for NULL Values A value equal to “nothing” must be placed in a batch file to indicate when to end.

40 Ch 1140 Testing for NULL Values NULL values … a user-defined value equivalent to nothing (no data).

41 Ch 1141 Testing for NULL Values Testing for a null value involves using the IF command with quotation marks.

42 Ch 1142 Testing for NULL Values Use quotation marks to test for null value: IF “%1” = = GOTO LABEL

43 Ch 1143 Testing for NULL Values “If nothing is there, GOTO somewhere else”

44 Ch 1144

45 Ch 1145 The IF EXIST/IF NOT EXIST Command IF EXIST/IF NOT EXIST command: checks for the existence or non-existence of a file.

46 Ch 1146

47 Ch 1147 The IF ERRORLEVEL Command Testing Exit code … a code set by a program that indicates a True or False condition when the program finishes executing.

48 Ch 1148 The IF ERRORLEVEL Command Testing IF ERRORLEVEL command… a statement in a batch file that can test exit codes.

49 Ch 1149 The IF ERRORLEVEL Command Testing An exit code is tested with ERRORLEVEL to determine if it is greater than or equal to it.

50 Ch 1150

51 Ch 1151 Writing Programs to Test for Key Codes Exit codes can be …  set by an operating system program  created by writing a small program

52 Ch 1152 Writing Programs to Test for Key Codes To write a program a user can …  use a programming language  use an OS utility called DEBUG

53 Ch 1153 Writing Programs to Test for Key Codes Easiest way to use DEBUG is to create a script file.

54 Ch 1154 Writing Programs to Test for Key Codes Script file … a set of instructions that can be written in any text editor.

55 Ch 1155

56 Ch 1156 The CHOICE Command CHOICE command … prompts the user to make a choice.

57 Ch 1157 The CHOICE Command Syntax for CHOICE command: CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] [text]

58 Ch 1158

59 Ch 1159 The Environment The environment …  is an area that the OS sets aside in memory  holds important info. that the OS needs to know

60 Ch 1160 The Environment Application programs can …  read any items in the environment  post their own messages there

61 Ch 1161 The Environment A user can leave a message there through …  the AUTOEXEC.BAT file  other batch files  the command line

62 Ch 1162 The Environment To leave a message, use the SET command.

63 Ch 1163 The Environment Syntax for SET command … SET [ variable = [string] ]

64 Ch 1164

65 Ch 1165 The DIRCMD Environmental Variable The DIRCMD command variable allows the user to preset, or change the way DIR displays information.

66 Ch 1166

67 Ch 1167 The FOR..IN..DO Command The FOR..IN..DO command can be …  issued at the command line  placed in a batch file

68 Ch 1168 The FOR..IN..DO Command FOR allows the use of a single command to issue several commands at once.

69 Ch 1169 The FOR..IN..DO Command Syntax for the FOR..IN..DO command at the command line: FOR %variable IN (set) DO command [command-parameters]

70 Ch 1170 The FOR..IN..DO Command Syntax for the FOR..IN..DO command in a batch program: FOR %variable IN (set) DO command [command-parameters]

71 Ch 1171

72 Ch 1172 The CALL Command CALL command … calls (executes) one batch program from another without causing first batch program to stop.

73 Ch 1173


Download ppt "Ch 111 Chapter 11 Advanced Batch Files. Ch 112 Overview This chapter focuses on batch file commands that allow you to:  write sophisticated batch files."

Similar presentations


Ads by Google