mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-15 11:10:54 +01:00
Update list-folder.ps1
This commit is contained in:
parent
0cb33ec99b
commit
6abf457fb3
@ -1,36 +1,47 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Lists the folder content
|
||||
Lists a folder
|
||||
.DESCRIPTION
|
||||
This PowerShell script lists the directory content formatted in columns.
|
||||
This PowerShell script lists the content of a directory (alphabetically formatted in columns).
|
||||
.PARAMETER SearchPattern
|
||||
Specifies the search pattern, "*" by default (means anything)
|
||||
Specifies the search pattern ("*" by default which means anything)
|
||||
.EXAMPLE
|
||||
PS> ./list-folder C:\
|
||||
PS> ./list-folder C:\*
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
param([string]$SearchPattern = "*")
|
||||
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" }
|
||||
function GetFileIcon { param([string]$suffix)
|
||||
switch ($suffix) {
|
||||
".csv" { return "📊" }
|
||||
".epub" { return "📓" }
|
||||
".gif" { return "🎨" }
|
||||
".iso" { return "📀" }
|
||||
".jpg" { return "🎨" }
|
||||
".mp3" { return "🎵" }
|
||||
".mp4" { return "🎬" }
|
||||
".mkv" { return "🎬" }
|
||||
".ps1" { return "📑" }
|
||||
default { return "📄" }
|
||||
}
|
||||
}
|
||||
|
||||
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 = "📂" } else { $icon = GetFileIcon $item.Extension }
|
||||
New-Object PSObject -property @{ Name = "$icon$name" }
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
ListFolder $SearchPattern | format-wide -autoSize
|
||||
ListFolder $searchPattern | Format-Wide -autoSize
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
Loading…
Reference in New Issue
Block a user