I have a batch file as follows:
myfile.bat
:: This is a sample batch file
@echo off
echo change directory to d: <---How to change color of only this line
There is no built-in way of doing this. I suggest you write yourself a little helper program which either changes the color attributes of text to come or writes some text with specific color attributes.
In C# this could look like the following:
using System;
class SetConsoleColor {
static void Main(string[] args) {
if (args.Length < 3) {
Console.Error.WriteLine("Usage: SetConsoleColor [foreground] [background] [message]");
return;
}
Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), args[0], true);
Console.BackgroundColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), args[1], true);
Console.WriteLine(args[2]);
Console.ResetColor();
}
}
Feel free to port to C or another language you like; this was just the fastest way for me after struggling with a 50-line C monster which still didn't work ;-).