![]() |
|
The anatomy of a Batch file For begginers only - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: The anatomy of a Batch file For begginers only (/Thread-The-anatomy-of-a-Batch-file-For-begginers-only) |
The anatomy of a Batch file For begginers only - Guts666 - 08-21-2011 Anatomy of a batch file As you've seen, batch files are essentially simple programs, using the built in command prompt commands as a programming 'library'. Each line in a batch file is executed sequentially, and they do not have to be numbered or otherwise identified. The computer simply reads the whole file from top to bottom and performs any commands the batch file contains. In addition to the standard command prompt commands that can be used in batch files, there are a few additional extras like the '@ECHO off' command we used in the last batch file we created. These can be used to modify how a batch file works. Let's run through some of them with examples of how they work: Additional Batch file commands Call Can be used to call another batch file from within the current one call c:\batchfile2.bat Echo Used to display information and commands on the screen or prevent them from being displayed. Echo on causes all commands in the batch file to be displayed onscreen. This is the default setting. @Echo off causes no commands to be displayed. The batch file will run silently unless you use the echo command specifically as below. echo what you want on the screen Causes whatever text comes after the echo command on the same line to be printed on the screen. For Used to select a specific set of files and run a command on each of them. for (variable) in (set of files) do (command) In another example, the batch file line; for %%F in (*.txt) do del "%%F" Gives the variable '%%F' the value of every file ending in .txt in the current directory, then passes that variable to the DEL command. This means that every file with the .txt extension in the current directory will be deleted. Goto Moves to different points within a batch file. The destination point must be indicated with a colon. For example… goto end :end echo this is the end, beautiful friend… the end :epic: dont forget to say thanks |