【问题标题】:Is it possible to get colour highlighting with the Powershell dir command是否可以使用 Powershell dir 命令获得颜色突出显示
【发布时间】:2010-11-10 19:15:00
【问题描述】:

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

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

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

【问题讨论】:

标签: powershell


【解决方案1】:

是的,这很容易做到。

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

【讨论】:

    猜你喜欢
    • 2020-03-24
    • 1970-01-01
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 2011-07-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多