mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-10 05:17:44 +02:00
Rename list-dir.ps1 to list-folder.ps1
This commit is contained in:
38
Scripts/list-folder.ps1
Executable file
38
Scripts/list-folder.ps1
Executable file
@ -0,0 +1,38 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Lists the folder content
|
||||
.DESCRIPTION
|
||||
This script lists the directory content formatted in columns.
|
||||
.PARAMETER SearchPattern
|
||||
Specifies the search pattern, "*" by default (means anything)
|
||||
.EXAMPLE
|
||||
PS> ./list-folder C:\
|
||||
.NOTES
|
||||
Author: Markus Fleschutz · License: CC0
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
#>
|
||||
|
||||
param([string]$SearchPattern = "*")
|
||||
|
||||
function ListFolder { param([string]$SearchPattern)
|
||||
$Items = get-childItem -path "$SearchPattern"
|
||||
foreach ($Item in $Items) {
|
||||
$Name = $Item.Name
|
||||
if ($Name[0] -eq '.') { continue } # hidden file/dir
|
||||
if ($Item.Mode -like "d*") { $Icon = "📂"
|
||||
} elseif ($Name -like "*.iso") { $Icon = "📀"
|
||||
} elseif ($Name -like "*.mp3") { $Icon = "🎵"
|
||||
} elseif ($Name -like "*.epub") { $Icon = "📓"
|
||||
} else { $Icon = "📄" }
|
||||
new-object PSObject -Property @{ Name = "$Icon$Name" }
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
ListFolder $SearchPattern | format-wide -autoSize
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
||||
exit 1
|
||||
}
|
Reference in New Issue
Block a user