PowerShell/docs/list-special-folders.md

109 lines
3.4 KiB
Markdown
Raw Normal View History

2023-07-29 10:34:04 +02:00
*list-special-folders.ps1*
================
2022-11-17 20:02:26 +01:00
list-special-folders.ps1
2022-11-17 19:46:02 +01:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2022-11-17 19:46:02 +01:00
```powershell
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
2023-07-29 10:04:38 +02:00
Script Content
--------------
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
<#
.SYNOPSIS
Lists special folders
.DESCRIPTION
2023-05-26 12:20:18 +02:00
This PowerShell script lists all special folders (sorted alphabetically).
2022-11-17 20:02:26 +01:00
.EXAMPLE
2023-08-06 21:36:33 +02:00
PS> ./list-special-folders.ps1
2022-11-17 20:02:26 +01:00
Folder Name Folder Path
----------- -----------
AdminTools 📂C:\Users\Markus\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Administrative Tools
...
.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" }
2023-05-26 12:20:18 +02:00
if ($IsLinux) { return "/tmp/" }
2022-11-17 20:02:26 +01:00
return "C:\Temp"
}
2023-10-19 08:12:00 +02:00
function TryFolder([string]$name, [string]$path) {
if (Test-Path "$path" -pathType container) {
New-Object PSObject -property @{ 'Folder Name' = "$name"; 'Folder Path' = "📂$path" }
2023-05-26 12:20:18 +02:00
}
2022-11-17 20:02:26 +01:00
}
function ListSpecialFolders {
if ($IsLinux) {
2023-10-19 08:12:00 +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"
TryFolder "Scripts" "$PSScriptRoot"
TryFolder "Snaps" "$HOME/snap"
TryFolder "SSH keys" "$HOME/.ssh"
TryFolder "System boot" "/boot"
TryFolder "System binaries" "/sbin"
TryFolder "System devices" "/dev"
TryFolder "System logs" "/var/log"
TryFolder "Trash" "$HOME/.local/share/Trash"
TryFolder "Templates" "$Home/Templates"
TryFolder "Temporary files" "$(GetTempDir)"
$path = Resolve-Path "$HOME/.."
TryFolder "Users" "$path"
TryFolder "Videos" "$HOME/Videos"
2022-11-17 20:02:26 +01:00
} else {
2023-10-19 08:12:00 +02:00
$folderNames = [System.Enum]::GetNames('System.Environment+SpecialFolder')
$folderNames | Sort-Object | ForEach-Object {
if ($path = [System.Environment]::GetFolderPath($_)) {
TryFolder "$_" "$path"
2022-11-17 20:02:26 +01:00
}
}
2023-10-19 08:12:00 +02:00
TryFolder "CrashDumps" "$HOME\AppData\Local\CrashDumps"
TryFolder "Repositories" "$HOME\source\repos"
TryFolder "Scripts" "$PSScriptRoot"
TryFolder "SSH keys" "$HOME\.ssh"
TryFolder "Temporary files" "$(GetTempDir)"
$path = Resolve-Path "$HOME/.."
TryFolder "Users" "$path"
2022-11-17 20:02:26 +01:00
}
}
try {
2023-10-19 08:12:00 +02:00
ListSpecialFolders | Format-Table -property @{e='Folder Name';width=22},'Folder Path'
2022-11-17 20:02:26 +01:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2023-10-19 08:12:00 +02:00
*(generated by convert-ps2md.ps1 using the comment-based help of list-special-folders.ps1 as of 10/19/2023 08:11:40)*