Advanced Batch Coding III




Introduction: Advanced Batch Coding III

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
set /p "name=Name: "
echo %name%>name.txt
set /p name=echo %name%

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 -n 1 -w 100>nul

You must ping an invalid in address ( 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
Start hello.bat
Echo hello


@echo off
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 ) 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
Call hello
Goto exit
Echo hello

( call can call a section in a batch file )

Step 6: More Batch

I have a collection of batch codes here

And I will be publishing tutorial 4 soon with super advanced batch coding!

Be the First to Share


    • The 1000th Contest

      The 1000th Contest
    • Battery Powered Contest

      Battery Powered Contest
    • Hand Tools Only Challenge

      Hand Tools Only Challenge

    6 Discussions


    Tip 2 years ago on Step 4

    You can also use "ping localhost -n 1 >nul". This is not exactly 1 second, but is close to it and can save you time.


    4 years ago

    please comment and post your codes here :)


    Reply 4 years ago

    Why do it needs a . after echo?

    And if seems that it should be hello.txt instead of hello.text and that it needs one quote in the third line.

    Thank you!


    Reply 4 years ago

    thank you I will fix these mistake auto correct has been fixing things that aren't wrong. As for the "." after echo I would try skipping the period I'm not sure if it is needed but on it said to include the period.

    Governor Keagan
    Governor Keagan

    4 years ago

    Do you have tutorials for the for command


    Reply 4 years ago

    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 :)