PowerShell/scripts/list-special-folders.ps1

86 lines
2.9 KiB
PowerShell
Raw Normal View History

2023-10-31 11:25:11 +01:00
<#
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"
}
2023-10-05 20:50:49 +02:00
function TryFolder([string]$name, [string]$path) {
if (Test-Path "$path" -pathType container) {
New-Object PSObject -property @{ 'Folder Name' = "$name"; 'Folder Path' = "📂$path" }
2022-12-28 14:47:29 +01:00
}
2022-09-25 10:13:38 +02:00
}
2022-09-19 14:15:58 +02:00
function ListSpecialFolders {
if ($IsLinux) {
2023-10-05 20:50:49 +02:00
TryFolder "Config files" "/etc"
TryFolder "Desktop" "$HOME/Desktop"
TryFolder "Documents" "$HOME/Documents"
TryFolder "Downloads" "$HOME/Downloads"
TryFolder "Dropbox" "$HOME/Dropbox"
TryFolder "Home" "$HOME"
TryFolder "Mount points" "/mnt"
TryFolder "Music" "$HOME/Music"
TryFolder "Optional packages" "/opt"
TryFolder "Pictures" "$HOME/Pictures"
TryFolder "Recovered files" "/lost+found"
TryFolder "Removable media" "/media"
TryFolder "Repositories" "$HOME/Repos"
TryFolder "Repositories" "$HOME/Repositories"
TryFolder "Root" "/"
TryFolder "Screenshots" "$HOME/Pictures/Screenshots"
2023-10-06 10:56:53 +02:00
TryFolder "Scripts" "$PSScriptRoot"
2023-10-06 11:51:36 +02:00
TryFolder "Snaps" "$HOME/snap"
TryFolder "SSH keys" "$HOME/.ssh"
2023-10-06 11:44:55 +02:00
TryFolder "System boot" "/boot"
2023-10-05 20:50:49 +02:00
TryFolder "System binaries" "/sbin"
2023-10-06 11:44:55 +02:00
TryFolder "System devices" "/dev"
TryFolder "System logs" "/var/log"
2023-10-05 20:50:49 +02:00
TryFolder "Trash" "$HOME/.local/share/Trash"
TryFolder "Templates" "$Home/Templates"
2023-10-06 11:51:36 +02:00
TryFolder "Temporary files" "$(GetTempDir)"
2023-10-06 10:56:53 +02:00
$path = Resolve-Path "$HOME/.."
TryFolder "Users" "$path"
2023-10-05 20:50:49 +02:00
TryFolder "Videos" "$HOME/Videos"
2022-09-19 14:15:58 +02:00
} else {
2023-10-06 10:56:53 +02:00
$folderNames = [System.Enum]::GetNames('System.Environment+SpecialFolder')
$folderNames | Sort-Object | ForEach-Object {
if ($path = [System.Environment]::GetFolderPath($_)) {
TryFolder "$_" "$path"
2022-09-25 10:58:46 +02:00
}
}
TryFolder "CrashDumps" "$HOME\AppData\Local\CrashDumps"
2023-10-06 10:56:53 +02:00
TryFolder "Repositories" "$HOME\source\repos"
TryFolder "Scripts" "$PSScriptRoot"
2023-10-06 11:51:36 +02:00
TryFolder "SSH keys" "$HOME\.ssh"
TryFolder "Temporary files" "$(GetTempDir)"
2023-10-06 10:56:53 +02:00
$path = Resolve-Path "$HOME/.."
TryFolder "Users" "$path"
2022-09-19 14:15:58 +02:00
}
}
try {
2023-10-15 19:58:31 +02:00
ListSpecialFolders | Format-Table -property @{e='Folder Name';width=22},'Folder Path'
2022-09-19 14:15:58 +02:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
2023-10-15 19:58:31 +02:00
}