Update list-dir-tree.ps1

This commit is contained in:
Markus Fleschutz 2023-01-09 13:48:04 +01:00
parent 4db1c30d76
commit ccdd85c14d

View File

@ -15,22 +15,32 @@
param([string]$DirTree = "$PWD")
function GetFileIcon { param([string]$Suffix)
switch ($Suffix) {
".csv" { return "📊" }
".epub" { return "📓" }
".gif" { return "🎨" }
".iso" { return "📀" }
".jpg" { return "🎨" }
".mp3" { return "🎵" }
".mkv" { return "🎬" }
default { return "📄" }
}
}
function ListDir { param([string]$Directory, [int]$Depth)
$Depth++
$Items = Get-ChildItem -path $Directory
foreach($Item in $Items) {
$Filename = $Item.Name
for ($i = 1; $i -lt $Depth; $i++) { Write-Host "" -noNewline }
for ($i = 1; $i -lt $Depth; $i++) { Write-Host "" -noNewline }
if ($Item.Mode -like "d*") {
Write-Host "├─" -noNewline
Write-Host "" -noNewline
Write-Host -foregroundColor green "📂$Filename"
ListDir "$Directory\$Filename" $Depth
$global:Dirs++
} else {
if ($Filename -like "*.iso") { $Icon = "📀"
} elseif ($Filename -like "*.mp3") { $Icon = "🎵"
} elseif ($Filename -like "*.epub") { $Icon = "📓"
} else { $Icon = "📄" }
$Icon = GetFileIcon $Item.Extension
Write-Host "$($Icon)$Filename ($($Item.Length) bytes)"
$global:Files++
$global:Bytes += $Item.Length