开发人员技术 | Windows 窗体
一组用于开发图形用户界面的 .NET Framework 托管库。
我自己写了一个powershell命令行脚本用于输出目录,但是powershell似乎不支持输出emoji,有什么解决方案吗?
这是我的命令脚本:
# 设置输出编码
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
# 参数
param(
[string]$Path,
[int]$Depth,
[switch]$IconMode
)
if (-not $Path) { $Path = "." }
if (-not $Depth) { $Depth = 1 } # 与 tree -L 默认行为一致
function Get-Icon {
param ([IO.FileSystemInfo]$Item)
if ($Item.PSIsContainer) { return "📁" }
$ext = $Item.Extension.ToLower()
switch ($ext) {
".txt" { "📄" }
".md" { "📄" }
".json" { "📄" }
".xml" { "📄" }
".exe" { "🧱" }
".dll" { "🧱" }
".bin" { "🧱" }
".mp3" { "🎵" }
".wav" { "🎵" }
".mp4" { "🎬" }
".mov" { "🎬" }
".avi" { "🎬" }
".jpg" { "🖼" }
".jpeg" { "🖼" }
".png" { "🖼" }
".gif" { "🖼" }
".zip" { "📦" }
".rar" { "📦" }
".7z" { "📦" }
".pdf" { "📚" }
".doc" { "📚" }
".docx" { "📚" }
default { "📄" }
}
}
function Print-Tree {
param (
[string]$Dir,
[string]$Prefix = "",
[int]$Level = 1 # 注意:从 1 开始,表示第一层内容(与 tree 一致)
)
# tree -L 1:只显示第一层内容,不进入第二层
if ($Level -gt $Depth) { return }
$items = Get-ChildItem $Dir
for ($i=0; $i -lt $items.Count; $i++) {
$item = $items[$i]
$isLast = ($i -eq $items.Count - 1)
$symbol = if ($isLast) { "└── " } else { "├── " }
if ($IconMode) {
$icon = Get-Icon -Item $item
Write-Output "$Prefix$symbol$icon $($item.Name)"
}
else {
Write-Output "$Prefix$symbol$($item.Name)"
}
# 递归:只有目录才继续展示下一层
if ($item.PSIsContainer) {
$childPrefix = if ($isLast) { "$Prefix " } else { "$Prefix│ " }
Print-Tree -Dir $item.FullName -Prefix $childPrefix -Level ($Level + 1)
}
}
}
# 输出根目录名(与 tree 命令一致)
Write-Output (Resolve-Path $Path)
# 执行
Print-Tree -Dir (Resolve-Path $Path)
但是输出就没有: