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
|
|
|
|
PS> ./list-special-folders
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
|
|
|
function AddLine { param([string]$FolderName, [string]$FolderPath)
|
2023-05-26 12:20:18 +02:00
|
|
|
if (Test-Path "$FolderPath" -pathType container) {
|
|
|
|
New-Object PSObject -property @{ 'Folder Name' = "$FolderName"; 'Folder Path' = "📂$FolderPath" }
|
|
|
|
}
|
2022-11-17 20:02:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function ListSpecialFolders {
|
|
|
|
if ($IsLinux) {
|
2023-05-26 12:20:18 +02: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/"
|
|
|
|
AddLine "Repositories" "$HOME/Repos/"
|
|
|
|
AddLine "Repositories" "$HOME/Repositories/"
|
|
|
|
AddLine "Screenshots" "$HOME/Pictures/Screenshots/"
|
|
|
|
AddLine "Snap" "$HOME/snap/"
|
|
|
|
AddLine "SSH" "$HOME/.ssh/"
|
|
|
|
AddLine "Trash" "$HOME/.local/share/Trash/"
|
|
|
|
AddLine "Templates" "$Home/Templates/"
|
|
|
|
AddLine "Temporary" "$(GetTempDir)"
|
2022-11-17 20:02:26 +01:00
|
|
|
$Path = Resolve-Path "$HOME/.."
|
2023-05-26 12:20:18 +02:00
|
|
|
AddLine "Users" "$Path/"
|
|
|
|
AddLine "Videos" "$HOME/Videos/"
|
2022-11-17 20:02:26 +01:00
|
|
|
} else {
|
|
|
|
$FolderNames = [System.Enum]::GetNames('System.Environment+SpecialFolder')
|
|
|
|
$FolderNames | Sort-Object | ForEach-Object {
|
|
|
|
if ($Path = [System.Environment]::GetFolderPath($_)) {
|
|
|
|
AddLine "$_" "$Path"
|
|
|
|
}
|
|
|
|
}
|
2023-05-26 12:20:18 +02:00
|
|
|
AddLine "Repositories" "$HOME\source\repos"
|
|
|
|
AddLine "SSH" "$HOME\.ssh"
|
|
|
|
AddLine "Temporary" "$(GetTempDir)"
|
2022-11-17 20:02:26 +01:00
|
|
|
$Path = Resolve-Path "$HOME/.."
|
|
|
|
AddLine "Users" "$Path"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-05-26 12:20:18 +02:00
|
|
|
ListSpecialFolders | Format-Table -property @{e='Folder Name';width=18},'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-08-06 11:42:46 +02:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of list-special-folders.ps1 as of 08/06/2023 11:42:29)*
|