Blogs Tutorial

Coding with Batch Files [.BAT]

  • 1,793 views • 1 today
  • 4
  • 1
  • 6
Twinklez
Level 76 : Legendary Modder
327
Just giving this advice out.
Batch = Bat.

Like .bat files.
How to create one.
Make a TXT file. Then SAVE AS it.
Make it *.bat
* = anyname you want.
Remember to put it on All Programs!

Batch is pretty easy to begin with.

echo means like echo or talk.

If you don't want people to see random echo methods then put

@echo off

and

title WHATEVER U WANT

and

color WHATEVERCOLOR [number] ex. 01 02 0f 03 etc.

Statements

echo = talk (ex. echo hi)
pause = pause so u can read it (ex. pause)
choice = make people choose between Yes/No. (ex. choice)
if = Like if (ex. if not defined statement)
title = the title (ex. title Program)
color = the color (ex. color 03)
You can also use &3.
:* = Set a location. [* = anyname] (ex. :start)
goto = Go to a set location. MUST BE CREATED. (ex. goto start)
cls = clear screen (ex. cls)
set = Set.. :P (ex. set)
/p *= = Make a command entrance. (ex. /p password=)
IT MUST BE /p
nul = Null / Nothing / Terminate clear stuff. (ex. pause > nul)
pause > nul means won't show the PAUSE.

Double % around an already stated statement causes it to display the statement.
Example in ExampleBat.



Special Statements

How to make you wait before putting another command down.
ping 0 -n 1 > nul

[The "1" stands for 1 second]
You can change it to whatever you want.

echo BlahBlahBlah > Blah.txt
echo Blah... >> Blah.txt

That creates a TXT file inside the directory your in when you run your bat file.
It should say BlahBlahBlah then a new line Blah... >> Blah.txt
The double > stands for save the last line and make a new line.

That's basically the very simple commands, much more will be added soon.
This is nothing like JAVA I know :D


ExampleBat File:

@echo off
title Tutorial
color 03
:start

echo Hello, please enter your username!
set /p username=
echo Saved your username!
cls
if not defined username (
goto start
)

:menustart
echo Welcome %username%!
echo Please choose a number!
echo 1) Delete Everything
echo 2) Install Everything
set /p menu=
cls
if %menu% == 1 goto delete
if %menu% == 2 goto install
cls

:delete

echo Deleting all files. Please wait...
ping 0 -n 5 > nul
echo Completed! Program terminated!
pause
cls
goto exit

:install
echo Installing all files. Please wait...
ping 0 -n 5.5 > nul
echo Completed! All things have successfully installed!
pause
cls
goto menustart

:exit
pause

This batch file right here I just wrote asks for a username then when it is defined it goes on, if it is not defined it goes back to the beginning.

After it has been defined it will say Welcome THEUSERNAME.
Then it asks if you want to choose 1 or 2.

After each of them they should AUTO delete the screen because of cls.

If you choose 1. Like type in 1 and press Enter.
Then it goes to Delete, which displays delete messages but absolutely does nothing because this is
a test tutorial -ish. It says its deleting waits for 5 seconds then goes to exit. Which exits the whole thing :)
Somethings pause can be useful at the end of the code!

If you choose 2, then it goes to install. Just like before it says its installing then waits 5.5 seconds but does nothing because once again, it's a simple tutorial! After 5.5 seconds has past it will go to menustart.
Which goes back to ask you to choose 1 or 2.

Try it copy and paste it onto a BAT file! :D
This is a super simple BAT file you can do much more things if you try :D

IF YOU STILL NEED HELP, PLEASE COMMENT BELOW OR PM ME! :D
Tags

1 Update Logs

Statements : by Twinklez 02/16/2013 2:38:23 pmFebruary 16, 2013 @ 7:38 pm UTC

Added a few extra statements.

  Have something to say?

tobbestark
09/09/2015 3:18 am
Level 45 : Master Architect
Nice tutorial, dude! But what's this programming language called?
1
Twinklez
09/09/2015 5:43 pm
Level 76 : Legendary Modder
It's a shell script, more of a Windows thing.
1
mcrocks999
12/06/2013 3:25 pm
Level 20 : Expert Cake
Great tutorials :D
1
gabe4356
07/30/2013 11:37 pm
Level 53 : Grandmaster Blob
you know you could just say coding with dos
1
DerpyZ
03/08/2013 4:25 pm
Level 15 : Journeyman Lava Rider
*Note* color codes with .bat files are the same color codes in minecraft.
1
Twinklez
03/08/2013 4:55 pm
Level 76 : Legendary Modder
I know, I didn't put everything. I'll add that on.
1

Welcome