mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-27 23:42:00 +02:00
Update list-dir-tree.ps1
This commit is contained in:
parent
2f8620c610
commit
64b95af3e0
@ -1,8 +1,8 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Lists the full directory tree
|
Lists the directory tree content
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script lists the full directory tree.
|
This PowerShell script lists all files and folders in a directory tree.
|
||||||
.PARAMETER DirTree
|
.PARAMETER DirTree
|
||||||
Specifies the path to the directory tree
|
Specifies the path to the directory tree
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
@ -17,21 +17,17 @@ param([string]$DirTree = "$PWD")
|
|||||||
|
|
||||||
function ListDir { param([string]$Directory, [int]$Depth)
|
function ListDir { param([string]$Directory, [int]$Depth)
|
||||||
$Depth++
|
$Depth++
|
||||||
$Items = get-childItem -path $Directory
|
$Items = Get-ChildItem -path $Directory
|
||||||
foreach ($Item in $Items) {
|
foreach($Item in $Items) {
|
||||||
$Filename = $Item.Name
|
$Filename = $Item.Name
|
||||||
|
for ($i = 1; $i -lt $Depth; $i++) { Write-Host "│ " -noNewline }
|
||||||
if ($Item.Mode -like "d*") {
|
if ($Item.Mode -like "d*") {
|
||||||
for ($i = 0; $i -lt $Depth; $i++) {
|
Write-Host "├─" -noNewline
|
||||||
write-host -nonewline "+--"
|
Write-Host -foregroundColor green "📂$Filename"
|
||||||
}
|
|
||||||
write-host -foregroundColor green "📂$Filename"
|
|
||||||
ListDir "$Directory\$Filename" $Depth
|
ListDir "$Directory\$Filename" $Depth
|
||||||
$global:Dirs++
|
$global:Dirs++
|
||||||
} else {
|
} else {
|
||||||
for ($i = 1; $i -lt $Depth; $i++) {
|
Write-Host "├ $Filename ($($Item.Length) bytes)"
|
||||||
write-host -nonewline "| "
|
|
||||||
}
|
|
||||||
write-host "|-$Filename ($($Item.Length) bytes)"
|
|
||||||
$global:Files++
|
$global:Files++
|
||||||
$global:Bytes += $Item.Length
|
$global:Bytes += $Item.Length
|
||||||
}
|
}
|
||||||
@ -43,9 +39,9 @@ try {
|
|||||||
[int]$global:Files = 0
|
[int]$global:Files = 0
|
||||||
[int]$global:Bytes = 0
|
[int]$global:Bytes = 0
|
||||||
ListDir $DirTree 0
|
ListDir $DirTree 0
|
||||||
write-host "($($global:Dirs) directories, $($global:Files) files, $($global:Bytes) bytes total)"
|
"($($global:Dirs) folders, $($global:Files) files, $($global:Bytes) bytes total)"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user