3

On the Mac or Linux terminal it is possible to get colour listings of directory contents; files are a different colour from folders, for instance (ignoring the quotes used for Stackoverflow colouration):

>ls
README.md 'src' 'tests' .gitignore

Is it possible to similarly color highlight the output of the Get-ChildItem command in Powershell?

John Kane
  • 3,601
  • 5
  • 23
  • 18
  • 2
    Not right out of the box but with a little effort it is possible. See these two questions/answers: http://stackoverflow.com/questions/4126409/how-to-write-a-list-sorted-lexicographically-in-a-grid-listed-by-column http://stackoverflow.com/questions/3420731/powershell-colored-directory-listing-is-incorrect-with-format-wide – Roman Kuzmin Nov 10 '10 at 20:15
  • You probably wanted the answer of this question: http://stackoverflow.com/questions/9406434/powershell-properly-coloring-get-childitem-output-once-and-for-all – jhclark Apr 07 '14 at 15:43

1 Answers1

0

Yes, this is quite easy to do.

$List = gci –path 'C:\yourpathhere\' -rec
foreach ($item in $List) {
    if ($item.PSIsContainer) {
        write-host $item.Name -foregroundcolor "magenta" 
    } else {
        write-host $item.Name -foregroundcolor "yellow"
    }
}
D3vtr0n
  • 2,774
  • 3
  • 33
  • 53