diff --git a/scripts/list-dir-tree.ps1 b/scripts/list-dir-tree.ps1 index fe7b56cc..57760e97 100755 --- a/scripts/list-dir-tree.ps1 +++ b/scripts/list-dir-tree.ps1 @@ -1,15 +1,15 @@ ο»Ώ<# .SYNOPSIS - Lists a dir tree + Lists a directory tree .DESCRIPTION - This PowerShell script lists all files and folders in a neat directory tree (including icon and size). + This PowerShell script lists all files and folders in a directory tree (including icon and size). .PARAMETER path - Specifies the path to the directory tree + Specifies the file path to the directory tree .EXAMPLE PS> ./list-dir-tree.ps1 C:\MyFolder β”œπŸ“‚Results β”‚ β”œπŸ“„sales.txt (442K) - (2 folders, 1 file, 442K file size in total) + (2 folders, 1 file, 442K total) .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -49,32 +49,30 @@ function Bytes2String([int64]$bytes) { } function ListDir([string]$path, [int]$depth) { - $depth++ $items = Get-ChildItem -path $path foreach($item in $items) { - $filename = $item.Name - for ($i = 1; $i -lt $depth; $i++) { Write-Host "β”‚ " -noNewline } + Write-Host " " -noNewline + for ([int]$i = 1; $i -lt $depth; $i++) { Write-Host "β”‚ " -noNewline } if ($item.Mode -like "d*") { - Write-Output "β”œπŸ“‚$Filename" - ListDir "$path\$filename" $depth + Write-Host "β”œπŸ“‚$($item.Name)" + ListDir "$path\$($item.Name)" ($depth + 1) } else { - $icon = GetFileIcon $item.Extension - Write-Output "β”œ$($icon)$filename ($(Bytes2String $item.Length))" + Write-Host "β”œ$(GetFileIcon $item.Extension)$($item.Name) ($(Bytes2String $item.Length))" $global:files++ $global:bytes += $item.Length } } $global:folders++ + if ($depth -gt $global:depth) { $global:depth = $depth } } try { - [int64]$global:folders = 0 - [int64]$global:files = 0 - [int64]$global:bytes = 0 - ListDir $path 0 - Write-Output " ($($global:folders) folders, $($global:files) files, $(Bytes2String $global:bytes) total)" + Write-Host "`n πŸ“‚$path" + [int64]$global:files = $global:folders = $global:depth = $global:bytes = 0 + ListDir $path 1 + " ($($global:files) files, $($global:folders) folders, depth $($global:depth), $(Bytes2String $global:bytes) total)" exit 0 # success } catch { - "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + "⚠️ ERROR: $($Error[0]) in script line $($_.InvocationInfo.ScriptLineNumber)." exit 1 }