Sunday, June 30, 2013

1. Batch Files Tutorial for a C/C++ Programmer, Introduction, Batch File Comments, Commenting Multiple lines

In next few posts I would scribe about basics of batch files. The post heading :  "Batch Files Tutorial for a C/C++ Programmer", I have  chosen because I have presume that reader is aware of basic of programming terminologies.

When I type something in blue, consider that a batch file content.

Here we go.

Commands, Comments
-Each line in batch file is a command, A command ends with line feed character(Enter) 
e.g All of below are valid batch file commands

dir
md myDir

-You can comment a line by preceding a line by "::"
-You can also precede a line by "REM" also to comment a line
TIP: In notepad++, you can select multiple lines and press Ctrl+Q, it will comments all of those lines

::This is a comment
REM This is also a comment



Line is too Long what to Do
One line is batch file is interpretative as one command. But, incare lines gets too lengthy you can use ^ to break it to multiple lines

::Multi Line command, creates a directory named MyDir1
md ^
MyDir1


- DOS gives you some to you, e.g md, dir etc. You are also allowed to call other executables from
batch file. But make sure the program directory is present in path variable

- When you type any exe, DOS searches all the directories present in PATH. If DOS finds it, command is executed, otherwise command not found found message is dispalyed.

-If you want to avoid searching of these exes, you can give absolute path of exe

c:\Dir1\Dir2\myExe  


No comments: