Tuesday, November 26, 2019

windows 7 - Multicolored Batch File


I have this batch file i wrote, and i wrote it to make specific words to be different colors, as a test.


But so far, i can't get any farther than this, I'm stuck, and I was wanting to use it to make other words in different colors, to make a color coding scheme. But can't figure out how. I've honestly spent weeks trying to figure this one out but am having no luck.


Here is my code:


MD Color
CD Color
cls
echo Cool> "Text to Color"
echo Hello> "Test"
echo Test> "Helloo"
cls
FINDSTR /A:0c /C:"Cool" /S "Text to Color"
FINDSTR /A:0b /C:"Hello" /S "Test"
FINDSTR /A:0a /C:"Test" /S "Helloo"
CD..
RD /S /Q Color
@pause

The name of the file is "Text to Color.bat" in a folder named "Color"


Result


C:\Users\CST27\Dropbox\Color\Color>FINDSTR /A:0c /C:"Cool" /S "Text to Color"
Text to Color:Cool
C:\Users\CST27\Dropbox\Color\Color>FINDSTR /A:0b /C:"Hello" /S "Test"
Test:Hello
C:\Users\CST27\Dropbox\Color\Color>FINDSTR /A:0a /C:"Test" /S "Helloo"
Helloo:Test
C:\Users\CST27\Dropbox\Color\Color>CD..
C:\Users\CST27\Dropbox\Color>RD /S /Q Color
Press any key to continue . . .

With "text to color" in red, "test" in blue, and "Helloo" in green.


And I was wanting to maybe try and make the words after those in a different color as well.


Answer



Use Windows PowerShell instead of cmd.exe


Write-Host -ForegroundColor Red -Object "Hello";
Write-Host -BackgroundColor Blue -Object "World!";

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...