2022-09-19 14:15:58 +02:00
|
|
|
|
<#
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Lists special folders
|
|
|
|
|
.DESCRIPTION
|
2022-12-28 14:47:29 +01:00
|
|
|
|
This PowerShell script lists all special folders (sorted alphabetically).
|
2022-09-19 14:15:58 +02:00
|
|
|
|
.EXAMPLE
|
2023-08-06 21:35:36 +02:00
|
|
|
|
PS> ./list-special-folders.ps1
|
2022-09-19 14:15:58 +02:00
|
|
|
|
|
2022-09-25 10:13:38 +02:00
|
|
|
|
Folder Name Folder Path
|
|
|
|
|
----------- -----------
|
2022-09-25 10:58:46 +02:00
|
|
|
|
AdminTools 📂C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Administrative Tools
|
2022-09-19 14:15:58 +02:00
|
|
|
|
...
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
function GetTempDir {
|
|
|
|
|
if ("$env:TEMP" -ne "") { return "$env:TEMP" }
|
|
|
|
|
if ("$env:TMP" -ne "") { return "$env:TMP" }
|
2022-12-28 14:47:29 +01:00
|
|
|
|
if ($IsLinux) { return "/tmp/" }
|
2022-09-19 14:15:58 +02:00
|
|
|
|
return "C:\Temp"
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-25 10:13:38 +02:00
|
|
|
|
function AddLine { param([string]$FolderName, [string]$FolderPath)
|
2022-12-28 14:47:29 +01:00
|
|
|
|
if (Test-Path "$FolderPath" -pathType container) {
|
|
|
|
|
New-Object PSObject -property @{ 'Folder Name' = "$FolderName"; 'Folder Path' = "📂$FolderPath" }
|
|
|
|
|
}
|
2022-09-25 10:13:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-19 14:15:58 +02:00
|
|
|
|
function ListSpecialFolders {
|
|
|
|
|
if ($IsLinux) {
|
2022-12-28 14:47:29 +01:00
|
|
|
|
AddLine "Desktop" "$HOME/Desktop/"
|
|
|
|
|
AddLine "Documents" "$HOME/Documents/"
|
|
|
|
|
AddLine "Downloads" "$HOME/Downloads/"
|
|
|
|
|
AddLine "Dropbox" "$HOME/Dropbox/"
|
|
|
|
|
AddLine "Home" "$HOME/"
|
|
|
|
|
AddLine "Music" "$HOME/Music/"
|
|
|
|
|
AddLine "Pictures" "$HOME/Pictures/"
|
2022-12-28 15:00:09 +01:00
|
|
|
|
AddLine "Repositories" "$HOME/Repos/"
|
|
|
|
|
AddLine "Repositories" "$HOME/Repositories/"
|
2022-12-28 14:47:29 +01:00
|
|
|
|
AddLine "Screenshots" "$HOME/Pictures/Screenshots/"
|
|
|
|
|
AddLine "Snap" "$HOME/snap/"
|
2022-12-28 14:55:47 +01:00
|
|
|
|
AddLine "SSH" "$HOME/.ssh/"
|
2022-12-28 14:47:29 +01:00
|
|
|
|
AddLine "Trash" "$HOME/.local/share/Trash/"
|
|
|
|
|
AddLine "Templates" "$Home/Templates/"
|
|
|
|
|
AddLine "Temporary" "$(GetTempDir)"
|
2022-09-25 10:13:38 +02:00
|
|
|
|
$Path = Resolve-Path "$HOME/.."
|
2022-12-28 14:47:29 +01:00
|
|
|
|
AddLine "Users" "$Path/"
|
|
|
|
|
AddLine "Videos" "$HOME/Videos/"
|
2022-09-19 14:15:58 +02:00
|
|
|
|
} else {
|
2022-09-25 10:58:46 +02:00
|
|
|
|
$FolderNames = [System.Enum]::GetNames('System.Environment+SpecialFolder')
|
|
|
|
|
$FolderNames | Sort-Object | ForEach-Object {
|
|
|
|
|
if ($Path = [System.Environment]::GetFolderPath($_)) {
|
|
|
|
|
AddLine "$_" "$Path"
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-28 15:05:40 +01:00
|
|
|
|
AddLine "Repositories" "$HOME\source\repos"
|
|
|
|
|
AddLine "SSH" "$HOME\.ssh"
|
|
|
|
|
AddLine "Temporary" "$(GetTempDir)"
|
2022-09-25 10:13:38 +02:00
|
|
|
|
$Path = Resolve-Path "$HOME/.."
|
2022-09-25 10:58:46 +02:00
|
|
|
|
AddLine "Users" "$Path"
|
2022-09-19 14:15:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2022-12-28 14:47:29 +01:00
|
|
|
|
ListSpecialFolders | Format-Table -property @{e='Folder Name';width=18},'Folder Path'
|
2022-09-19 14:15:58 +02:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
2022-12-28 14:47:29 +01:00
|
|
|
|
}
|