forked from fleschutz/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist-folder.ps1
executable file
·38 lines (35 loc) · 1.03 KB
/
list-folder.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<#
.SYNOPSIS
Lists the folder content
.DESCRIPTION
This PowerShell script lists the directory content formatted in columns.
.PARAMETER SearchPattern
Specifies the search pattern, "*" by default (means anything)
.EXAMPLE
PS> ./list-folder C:\
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz / License: CC0
#>
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 in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}