Very Basic Batch Tutorial


If you already know the essentials of Batch the you DO NOT need to read this instructable continue to Not So Basic Batch Tutorial.

NOTE!: Whenever something is in quotation marks ("example"), do not include the quotation marks (if you see that you must just type: example)

Step 1: So, what is Batch

For those who don't know, a Batch file is a text file containing a series of commands to be executed by Command Prompt (CMD). When a batch file is run, CMD reads the file and executes its commands.

To open your CMD, click START > RUN > type "CMD" > OK
(some of you may need to type "CMD.EXE")
(or you can click START > ALL PROGRAMS > ACCESSORIES > COMMAND PROMPT).

Step 2: Now what?

These are some VERY basic commands you need to know:
(please try out some of these commands in your CMD).

@echo off - This gets rid of that "c:\documents...etc"

echo - This displays a message, (e.g "echo hello" = "hello") because if you type "hello" into CMD it will interpret "hello" as the command

cls - Clears the CMD of all text.

color - Changes the color (type "help color" for a list of colors).

goto - Goes to a particular word in your text (you will learn more later)

pause - Pauses the command prompt and displays the message: "Press any key to continue..."

and there are a few more we will learn about later.

Step 3: But what if I want to run a lot of commands.

Picture of But what if I want to run a lot of commands.
That is where BATCH comes in.

Try copying this into your notepad (NOT Microsoft Word) and save as BatchFile.bat
Notepad is in accessories
NB: You must save it as .BAT or it won't work.
P.S (copy BETWEEN the stars, don't include them)
***********************************************************
echo If you type echo before a sentence it displays it as a message!.
echo Wow, thats pretty cool!
***********************************************************
copy that into notepad and save as .bat
Double-click on the .bat file...cool hey!
NOPE. It went too fast...try adding a pause at the end, like this:
***********************************************************
echo If you type echo before a sentence it displays it as a message!.
echo Wow, thats pretty cool!
PAUSE
**************************************************************
There it worked, but its quite hard to read with all those file paths in the way...
thats why we add an "@echo off" to the top;
like this:
***************************************************************
@echo off
echo If you type echo before a sentence it displays it as a message!.
echo Wow, thats pretty cool!
PAUSE
*******************************************************
There! that worked perfectly, you have now written your first batch file!

Step 4: The GOTO command

Picture of The GOTO command
Now we will learn how to use the GOTO command.

The GOTO command jumps to a certain part of your text.
Example:
if you type "goto fish"
then it will goto the place that you have typed in ":fish"
NB: you must always have a colon (:), before a word that is going to be GOTO'ed

Example:
you know the drill, copy into notepad and save as a .bat file.
(do not copy the stars)
**************************************************
@echo off
:fish
echo This is only one message being repeated over and over; Press Ctrl+C to stop
goto fish
**************************************************
*Note: Ctrl+C is the universal way of stopping a batch file

What happened was that every time it typed "Press Ctrl...etc"
the GOTO command made it go to the top.
Pretty nifty eh?

Step 5: The START command

The START command starts something.
Not much to explain here.

For example:
open your CMD and type:
"start www.instructables.com"
This opens your default explorer and goes to the Instructables site.
OR
"start itunes"
OR
You can also open files or folders:
"start desktop\foldername

**NOTE: To access a file\folder which has spaces in the name, put quotation marks (" ") around it.
e.g start "C:\desktop\folder name"

More Tricks

Step 6: Done

Thanks folks, please continue to the Not So Basic Batch Tutorial.

0 comments:

Post a Comment

Thanks for commenting you will be respond early as possible..........your comment will be published after Moderation

 
Top