Changing the color of each line of output?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tbharber
Posts: 32
Joined: 17 Sep 2010 17:08

Changing the color of each line of output?

#1 Post by tbharber » 27 May 2013 20:59

Hey all!

I have a script that looks for a series of files. If they are found I want it to change the color of just that line to be green, and if it is not found, to be red. Below is a simplified version of the code I currently have. The problem is say file 1 is found and it is green, and if file 2 is missing, all of the text on the screen turns red instead of just that one line. What is the easiest way to have just the lines of the files that do not exist to be red, and the rest green?


Code: Select all

@echo off
cls
if exist c:\test1.txt (color 1a & echo File Exists) else (color 1c & echo File Missing)
if exist c:\test2.txt (color 1a & echo File Exists) else (color 1c & echo File Missing)
if exist c:\test3.txt (color 1a & echo File Exists) else (color 1c & echo File Missing)
if exist c:\test4.txt (color 1a & echo File Exists) else (color 1c & echo File Missing)

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Changing the color of each line of output?

#2 Post by Endoro » 27 May 2013 23:25


Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Changing the color of each line of output?

#3 Post by Aacini » 28 May 2013 10:02

You may use my ColorShow.exe auxiliary program that run much faster than Batch solutions. For example:

Code: Select all

if exist c:\test1.txt (ColorShow /1a "File Exists") else (ColorShow /1c "File Missing")
if exist c:\test2.txt (ColorShow /1a "File Exists") else (ColorShow /1c "File Missing")
if exist c:\test3.txt (ColorShow /1a "File Exists") else (ColorShow /1c "File Missing")
if exist c:\test4.txt (ColorShow /1a "File Exists") else (ColorShow /1c "File Missing")

Look for file 12-ColorShow.exe.hex at this site.

Antonio

Post Reply