Executing commands in a batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bala32
Posts: 1
Joined: 24 Sep 2014 07:15

Executing commands in a batch file

#1 Post by bala32 » 24 Sep 2014 07:29

Hi Friends,
if you put all of the commands in a text file in the same manner as in the above box, it becomes an executable program. Let's name it anyname.bat Similar to a COM or EXE command, you can simply type the name of this batch file at the DOS prompt to start your instructions. i.e. C:\>anyname or C:\>anyname.bat (note: the extension bat is optional here. It makes no difference, no matter you put it or not.)

DOS will then execute the commands automatically in the same order as written in the anyname.bat The followings are details of what DOS will do for you:-

Creates a new directory under the root called newdir
Copies all files under the DOS directory with an extension of EXE to the newly created newdir directory.
Changes the current directory to newdir directory
Display the directory listing of newdir directory
Changes the current directory to root directory

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: Executing commands in a batch file

#2 Post by Squashman » 24 Sep 2014 08:08

bala32 wrote:Let's name it anyname.bat Similar to a COM or EXE command, you can simply type the name of this batch file at the DOS prompt to start your instructions. i.e. C:\>anyname or C:\>anyname.bat (note: the extension bat is optional here. It makes no difference, no matter you put it or not.)

NOT TRUE!!!!!
1) You could have two files with the same name but different extensions in the folder. It will execute the first one it finds.
2) Naming your batch file is very critical as well. You don't ever want to name it the same as an already existing internal command that the operating system already uses. If you create a batch file that pings a computer and you call it ping.bat, you are not going to get the desired results you want because it will try to execute the ping.bat instead of the ping.exe command if you don't use the extensions.

Post Reply