是否可以使用Powershell dir命令获得颜色突出显示

时间:2010-11-10 19:15:01

标签: powershell

在Mac或Linux终端上,可以获取目录内容的颜色列表;例如,文件与文件夹的颜色不同(忽略用于Stackoverflow着色的引号):

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

是否可以在Powershell中以类似的颜色突出显示Get-ChildItem命令的输出?

1 个答案:

答案 0 :(得分:0)

是的,这很容易做到。

$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"
    }
}