Update list-special-folders.ps1

This commit is contained in:
Markus Fleschutz 2022-12-28 14:47:29 +01:00
parent d1075e3cdb
commit 705f9962ad

View File

@ -2,7 +2,7 @@
.SYNOPSIS .SYNOPSIS
Lists special folders Lists special folders
.DESCRIPTION .DESCRIPTION
This PowerShell script lists the special folders (sorted alphabetically). This PowerShell script lists all special folders (sorted alphabetically).
.EXAMPLE .EXAMPLE
PS> ./list-special-folders PS> ./list-special-folders
@ -19,27 +19,33 @@
function GetTempDir { function GetTempDir {
if ("$env:TEMP" -ne "") { return "$env:TEMP" } if ("$env:TEMP" -ne "") { return "$env:TEMP" }
if ("$env:TMP" -ne "") { return "$env:TMP" } if ("$env:TMP" -ne "") { return "$env:TMP" }
if ($IsLinux) { return "/tmp" } if ($IsLinux) { return "/tmp/" }
return "C:\Temp" return "C:\Temp"
} }
function AddLine { param([string]$FolderName, [string]$FolderPath) function AddLine { param([string]$FolderName, [string]$FolderPath)
New-Object PSObject -property @{ 'Folder Name' = "$FolderName"; 'Folder Path' = "📂$FolderPath" } if (Test-Path "$FolderPath" -pathType container) {
New-Object PSObject -property @{ 'Folder Name' = "$FolderName"; 'Folder Path' = "📂$FolderPath" }
}
} }
function ListSpecialFolders { function ListSpecialFolders {
if ($IsLinux) { if ($IsLinux) {
AddLine "Desktop" "$HOME/Desktop" AddLine "Desktop" "$HOME/Desktop/"
AddLine "Downloads" "$HOME/Downloads" AddLine "Documents" "$HOME/Documents/"
AddLine "Home Folder" "$HOME" AddLine "Downloads" "$HOME/Downloads/"
AddLine "MyDocuments" "$HOME/Documents" AddLine "Dropbox" "$HOME/Dropbox/"
AddLine "MyMusic" "$HOME/Music" AddLine "Home" "$HOME/"
AddLine "MyPictures" "$HOME/Pictures" AddLine "Music" "$HOME/Music/"
AddLine "MyScreenshots" "$HOME/Pictures/Screenshots" AddLine "Pictures" "$HOME/Pictures/"
AddLine "MyVideos" "$HOME/Videos" AddLine "Screenshots" "$HOME/Pictures/Screenshots/"
AddLine "Temporary Folder" "$(GetTempDir)" AddLine "Snap" "$HOME/snap/"
AddLine "Trash" "$HOME/.local/share/Trash/"
AddLine "Templates" "$Home/Templates/"
AddLine "Temporary" "$(GetTempDir)"
$Path = Resolve-Path "$HOME/.." $Path = Resolve-Path "$HOME/.."
AddLine "Users" "$Path" AddLine "Users" "$Path/"
AddLine "Videos" "$HOME/Videos/"
} else { } else {
$FolderNames = [System.Enum]::GetNames('System.Environment+SpecialFolder') $FolderNames = [System.Enum]::GetNames('System.Environment+SpecialFolder')
$FolderNames | Sort-Object | ForEach-Object { $FolderNames | Sort-Object | ForEach-Object {
@ -54,7 +60,7 @@ function ListSpecialFolders {
} }
try { try {
ListSpecialFolders | Format-Table -property @{e='Folder Name';width=22},'Folder Path' ListSpecialFolders | Format-Table -property @{e='Folder Name';width=18},'Folder Path'
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"