mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-25 08:09:17 +01:00
46 lines
1.1 KiB
PowerShell
Executable File
46 lines
1.1 KiB
PowerShell
Executable File
#!/snap/bin/powershell
|
|
<#
|
|
.SYNTAX ./visualize-dir-tree.ps1 [<dir-tree>]
|
|
.DESCRIPTION visualizes the given/current directory tree
|
|
.LINK https://github.com/fleschutz/PowerShell
|
|
.NOTES Author: Markus Fleschutz / License: CC0
|
|
#>
|
|
|
|
param([string]$DirTree = "")
|
|
|
|
function VisualizeDirectory { param([string]$Directory, [int]$Depth)
|
|
$Depth++
|
|
$Items = get-childItem -path $Directory
|
|
foreach ($Item in $Items) {
|
|
$Filename = $Item.Name
|
|
if ($Item.Mode -like "d*") {
|
|
for ($i = 0; $i -lt $Depth; $i++) {
|
|
write-host -nonewline "+--"
|
|
}
|
|
write-host -foregroundColor green "$Filename/"
|
|
VisualizeDirectory "$Directory\$Filename" $Depth
|
|
$global:NumDirs++
|
|
} else {
|
|
for ($i = 1; $i -lt $Depth; $i++) {
|
|
write-host -nonewline "| "
|
|
}
|
|
write-host "|-$Filename ($($Item.Length) bytes)"
|
|
$global:NumBytes += $Item.Length
|
|
}
|
|
}
|
|
}
|
|
|
|
try {
|
|
if ($DirTree -eq "") {
|
|
$DirTree = "$PWD"
|
|
}
|
|
$global:NumDirs = 1
|
|
$global:NumBytes = 0
|
|
VisualizeDirectory $DirTree 0
|
|
write-host "($($global:NumDirs) dirs, $($global:NumBytes) bytes total)"
|
|
exit 0
|
|
} catch {
|
|
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
exit 1
|
|
}
|