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