loading
This is super advanced batch coding; I will discuss echo and type for ascii graphics, I will discuss more if statements and I will discuss how to add delays in batch files
Tutorial I
Tuttorial II

Step 1: Echo and Type

We have already gone over the echo command but this is more advanced.

Echo. "This texted will be typed in a textfile"> hello.txt
Echo. "This will be line two">> hello.text
Echo. Three four five and so on">> hello.text


Add one ">" to make it the first line and 2 ">>" to make it on the next blank line.

Type types text into the cmd window and can be used to display text graphics

Type hello.text


Will display the contents of hello.text this can be used to display pictures of text.

Step 2: Saved Variables

@echo off
cls
set /p "name=Name: "
echo %name%>name.txt
set /p name=echo %name%
pause

This code asks the user to enter their name and sets it as %name%
The code then as seen in step one sends %name% to name.text
The code then calls name.text and searches for the variable name% and displays it. This can be used to store variable without making the user type them in every time

Step 3: If Statemnts III

We have gone over the if command twice but there is more to learn about the first is if /I.
The if /I command makes the letters A and a be interpreted the same way for example

If %word% == yes echo yes
If %word% == Yes echo yes

Can be changed to

If /I %word% == yes echo yes

This spares you a second line for the capital yes.

------------------------------------------------------------------------------------------------------

Step 4: Ping - Delay a Command

Pause waits for you to hit enter but ping allows for you to just wait view this line below

Ping 1.1.1.1 -n 1 -w 100>nul

You must ping an invalid in address ( 1.1.1.1) then the 100 will delay the batch file 1 second ( delay time is in miliseconds) and nul hides it the user also has no way to bypass ping they must wait the specified time.

Sleep - while I prefer ping sleep should still do the same thing ( sleep 1) measured in seconds.

Step 5: Call Vs Start

Start - start a file
Call - call a file ( but here's the difference )

@echo off
Cls
Start hello.bat
Echo hello
Pause

::Hello.bat

@echo off
Cls
Echo good bye

The first batch file will open hello.bat in the same window the problem is because hello.bat ends the first batch file will not continue ( you won't see the word hello ) to fix this problem use call

The call command will run hello.bat in the same windows but when hello.bat ends the first batch file will resume ( replace start with call ). So is start useless? No, start can be used to open a web page ( start google.com ) you can open a file such as a word document and you can edit a batch file using start notepad hello.bat ( open with notepad ). What else can call do? This

@echo off
Cls
Call hello
Goto exit
:hello
Echo hello
:exit

( call can call a section in a batch file )

Step 6: More Batch

I have a collection of batch codes here

https://www.instructables.com/id/Batch-codes/

And I will be publishing tutorial 4 soon with super advanced batch coding!
<p>please comment and post your codes here :)</p>
<p>Why do it needs a . after echo?</p><p>And if seems that it should be hello.txt instead of hello.text and that it needs one quote in the third line.</p><p>Thank you!</p>
<p>thank you I will fix these mistake auto correct has been fixing things that aren't wrong. As for the &quot;.&quot; after echo I would try skipping the period I'm not sure if it is needed but on stackoverflow.com it said to include the period.</p>
Do you have tutorials for the for command
<p>unfortunately I am unfamiliar with the for command so not yet I will work on compiling a tutorial for the for command and send you a message when it's ready :)</p>

About This Instructable

3,718views

23favorites

License:

More by Batchcc:Extract Pictures From Word Documents Save your flash game progress Batch safely store passwords 
Add instructable to: