Introduction: Different Colours in Batch Files

Picture of Different Colours in Batch Files

Everyone, with the help of g-one, I have created a function that you can install into your windows/system32 folder to get more than one colour in batch files.

Copy and paste the following code and save it as ncol.bat (this is very important that you save it exactly like that).

@echo off
setlocal
if "%~1"=="/?" (
echo.
echo    ncol ["Text"] [Colour]
echo.
echo "Text" - The text you want displayed in another colour.
echo          Remember that spaces cannot be added if you don't put the text in
echo          quotation marks (""^).
echo.
echo Colour - The hexadecimal colour code that you want the text to be changed into.
echo          For more information of colour codes, see "color /?"
echo.
exit /b
)
for /f "delims=#" %%i in ('"prompt #$H# &for %%b in (1) do rem"') do set "bs=%%i"
"%~1.@" set /p "=.%bs%%bs%%bs%%bs%"
findstr /p /a:%2 . "*.@"
endlocal
del "*.@"
@echo on
@exit /b


Once that is done, head over to your windows system32 folder and save it in there (C:\Windows\System32)

Read on for instructions...


Step 1: Instructions

Picture of Instructions
Ok, how to use this function.

Firstly, type it in as you would any command "ncol"

The first parameter is the text you want converted.

The second parameter is the colour (must be correspondent to the colour command).

Example:

ncol "Hello" 10

Would output:

Hello


Just try it!

Note: If you have spaces, you must use quotation marks ("").

P.S: type in "ncol /?" for more help.

Unfortunately, special characters cannot be converted yet... (~!@#$%^&*()_+=-/,.<>":;'[]\{}|`)

And there is a little glitch with it, but other than that... It's good to go!

--EDIT--
To add more colors onto one line, use the && operator. E.g: ncol "Hello " 12 && ncol "there" 23
would output "Hello " in one color, and "there" in another.

Comments

wilderness tech (author)2016-11-22

umm... when i do that i get

'"Hello.@"' is not recognized as an internal or external command,
operable program or batch file.
FINDSTR: Cannot open *.@
Could Not Find C:\Users\MyName\*.@

Mclover152 (author)2014-07-02

No its fine, i found a different program that does the same thing but works. I still like ur idea though.

Mclover152 (author)Mclover1522014-07-03

Im making a movement simulator game in batch (Kind of like Terraria) And for every block is a character (or piece of text). I really want to save myself from writing over 300 variables. So is there a way to have arrays in batch?

Batchcc (author)Mclover1522015-12-04

https://www.instructables.com/id/Multiple-colors-in...

That is a working version and where can I get that it sounds cool.

Batchcc (author)2015-12-04

Everyone I made a version that works view it here

https://www.instructables.com/id/Multiple-colors-in-cmd/

The Batchicle (author)2015-11-29

Hey Pickle! just wanted to say thanks because your instructables have really helped me with getting into batch but just a question. Why don't you create any more instructables? it would be really nice if you had more :)

The Batchicle (author)Batchcc2015-12-03

but he doesn't post anymore does he? his last post was maybe 1 or 2 years ago. He used to be the person who fixed all my codes that didn't work and now i have piles of not working code

Governor Keagan (author)2015-10-27

Thanks, I've been trying to find a code for this. I'm thinking of using it in my Trivia.

lhan5 (author)2015-04-15

You should add here the *.@ file that you have in your system32 because we need that and thats why it isnt working

Mclover152 (author)2014-06-29

It says the following when i type "ncol" in cmd.exe

'".@"' is not recognized as an internal or external command,

operable program or batch file.

FINDSTR: Argument missing after /a

Could not find C:\Users\****** ********\*.@

Prof. Pickle (author)Mclover1522014-06-29

NCOL is a function, meaning that you need to put in the name (ncol) and then the arguments. Type in "ncol /?" for more information.

Mclover152 (author)Prof. Pickle2014-06-29

It still doesn't work

Prof. Pickle (author)Mclover1522014-06-30

What exactly are you typing in? Are you still only putting in "ncol"?

Demon4511 (author)Prof. Pickle2014-07-01

He is most likely seeing this:

http://imgur.com/xf0MHJo

As am I! :(

Prof. Pickle (author)Demon45112014-07-02

As hard as I try, I can not recreate the issue on my computer. I don't really have any solid ideas as to why it is doing that for you and Mclover, but I will keep trying.

Mclover152 (author)Mclover1522014-06-30

I typed:
ncol "Hello World" 10

Mclover152 (author)2014-06-27

It didnt work for me :(

Prof. Pickle (author)Mclover1522014-06-27

It worked for me on Windows 8, 7 and vista. What operating system are you using?

Mclover152 (author)Prof. Pickle2014-06-28

It does not recognize "*.@"

Mclover152 (author)Prof. Pickle2014-06-28

Im using Windows Vista (32-bit)

Prof. Pickle (author)Mclover1522014-06-28

Can you describe what happens. Does nothing happen? Does it open and close? Does it display an error? Does it not work correctly?

Infinity__1 (author)2014-05-19

Never knew that this was possible. Sure helped making my programs more cooler.

Thanks.

code source (author)2012-12-22

Great instructable...
It's very new to me...

Prof. Pickle (author)code source2012-12-22

Thank you. I really appreciate any feedback I get (I assume you know that these topics are a low traffic area).

I've always wondered how to do it, and I owe it all to g-one for basically half of the code and the tutoring.

About This Instructable

26,755views

5favorites

License:

Bio: I enjoy anything to do with computers. I have made some interesting scripts, and I am constantly improving my skill set. One day I hope ... More »
More by Prof. Pickle:How to Create your own Commands with BatchStart a batch file completely hiddenTips on how to find errors in code (focused on DOS)
Add instructable to: