Good afternoon,
I have written a batch file which works great!
However, I would like to colour several pieces of text within the batch file.
I have spent a LONG time researching this on Google and I am almost there.
This is what I have at the top of the code...
This is what I have as an example that I want to colour red [which it does]...
This is what I have as the :ColorText code...
The questions I have are...
[1] If I put a colon [:] after Important, is doesn't work, hence the dash [-]?
[2] Why will it not show the exclamation [!] at the end of the line although it is there?
[3] Why will it not show the full stop [.] at the end of the line although it is there?
[4] Is there a way to split the call :ColorText 0c " IMPORTANT - Numbers 2 blah blah." over two lines so it makes it esaier to read and also lines up in the script with the code below it. I tried several options, all to no avail!
[5] As you see from the middle piece of code, the Numbers 2 and If you are not lined up, but they are in the consol!
[6] Why doesn't it put a blank row after even though there is a echo. after the text to be coloured, but it does if I use & set /p ".= " < nul end & echo..
[7] It will also not accept forward slash [/]!
Thanks in advance.
I have written a batch file which works great!
However, I would like to colour several pieces of text within the batch file.
I have spent a LONG time researching this on Google and I am almost there.
This is what I have at the top of the code...
Code:
@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
This is what I have as an example that I want to colour red [which it does]...
Code:
call :ColorText 0c " IMPORTANT - Numbers 2 blah blah."
call :ColorText 0c " If you blah blah!" & set /p ".= " < nul
echo.
This is what I have as the :ColorText code...
Code:
:ColorText
rem echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
GOTO :EOF
The questions I have are...
[1] If I put a colon [:] after Important, is doesn't work, hence the dash [-]?
[2] Why will it not show the exclamation [!] at the end of the line although it is there?
[3] Why will it not show the full stop [.] at the end of the line although it is there?
[4] Is there a way to split the call :ColorText 0c " IMPORTANT - Numbers 2 blah blah." over two lines so it makes it esaier to read and also lines up in the script with the code below it. I tried several options, all to no avail!
[5] As you see from the middle piece of code, the Numbers 2 and If you are not lined up, but they are in the consol!
[6] Why doesn't it put a blank row after even though there is a echo. after the text to be coloured, but it does if I use & set /p ".= " < nul end & echo..
[7] It will also not accept forward slash [/]!
Thanks in advance.
Last edited:
My Computer
- Computer type
- Laptop
- Computer Manufacturer/Model Number
- Fujitsu LIFEBOOK
- OS
- Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
- CPU
- Intel(R) Pentium(R) CPU P6200 @ 2.13GHz
- Motherboard
- FUJITSU FJNBB06
- Memory
- 4.00 GB
- Graphics Card(s)
- Intel(R) Graphics Media Accelerator HD
- Sound Card
- [1] Realtek High Definition Audio [2] Intel(R) Display Audio
- Screen Resolution
- 1366 x 768 x 32 bits (4294967296 colors) @ 59 Hz
- Hard Drives
- TOSHIBA MK5076GSX
- Antivirus
- AVG FREE