mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-26 16:48:54 +01:00
Add pattern to list-dir.ps1
This commit is contained in:
parent
c68563600a
commit
7e5bb4d636
@ -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])"
|
||||||
|
Loading…
Reference in New Issue
Block a user