Add pattern to list-dir.ps1

This commit is contained in:
Markus Fleschutz 2021-05-10 19:41:03 +02:00
parent c68563600a
commit 7e5bb4d636

View File

@ -1,14 +1,14 @@
<# <#
.SYNTAX list-dir.ps1 [<directory>] .SYNTAX list-dir.ps1 [<pattern>]
.DESCRIPTION lists the directory content formatted in columns .DESCRIPTION lists the directory content formatted in columns
.LINK https://github.com/fleschutz/PowerShell .LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
param($Directory = "$PWD") param($Pattern = "*")
function ListDir { param([string]$Path) function ListDir { param([string]$Pattern)
$Items = get-childItem -path $Path $Items = get-childItem -path "$Pattern"
foreach ($Item in $Items) { foreach ($Item in $Items) {
$Name = $Item.Name $Name = $Item.Name
if ($Name[0] -eq '.') { continue } # hidden file/dir if ($Name[0] -eq '.') { continue } # hidden file/dir
@ -22,7 +22,7 @@ function ListDir { param([string]$Path)
} }
try { try {
ListDir $Directory | format-wide -autoSize ListDir $Pattern | format-wide -autoSize
exit 0 exit 0
} catch { } catch {
write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"