From 6bc3e59a0d059c11fa24d54f4c29577599ef98d9 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Mon, 19 Sep 2022 14:15:58 +0200 Subject: [PATCH] Add list-special-folders.ps1 --- Scripts/list-special-folders.ps1 | 63 ++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Scripts/list-special-folders.ps1 diff --git a/Scripts/list-special-folders.ps1 b/Scripts/list-special-folders.ps1 new file mode 100644 index 00000000..e9a9a6c5 --- /dev/null +++ b/Scripts/list-special-folders.ps1 @@ -0,0 +1,63 @@ +<# +.SYNOPSIS + Lists special folders +.DESCRIPTION + This PowerShell script lists all special folders (sorted alphabetically). +.EXAMPLE + PS> ./list-special-folders + + Folder Name Folder Path + ----------- ----------- + Home Folder C:\Users\Markus + ... +.LINK + https://github.com/fleschutz/PowerShell +.NOTES + Author: Markus Fleschutz | License: CC0 +#> + +function AddLine { param([string]$FolderName, [string]$FolderPath) + New-Object PSObject -property @{ 'Folder Name' = "$FolderName"; 'Folder Path' = "$FolderPath" } +} + +function GetTempDir { + if ("$env:TEMP" -ne "") { return "$env:TEMP" } + if ("$env:TMP" -ne "") { return "$env:TMP" } + if ($IsLinux) { return "/tmp" } + return "C:\Temp" +} + +function ListSpecialFolders { + if ($IsLinux) { + AddLine "📂Desktop" "$HOME/Desktop" + AddLine "📂Downloads" "$HOME/Downloads" + AddLine "📂Home Folder" "$HOME" + AddLine "📂My Documents" "$HOME/Documents" + AddLine "📂My Music" "$HOME/Music" + AddLine "📂My Pictures" "$HOME/Pictures" + AddLine "📂My Screenshots" "$HOME/Pictures/Screenshots" + AddLine "📂My Videos" "$HOME/Videos" + AddLine "📂Temporary Folder" "$(GetTempDir)" + } else { + $Path = Resolve-Path "$HOME/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup" + AddLine "📂Autostart" "$Path" + AddLine "📂Desktop" "$([Environment]::GetFolderPath('DesktopDirectory'))" + AddLine "📂Downloads" "$((New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path)" + AddLine "📂Fonts" "$([Environment]::GetFolderPath('Fonts'))" + AddLine "📂Home Folder" "$HOME" + AddLine "📂My Documents" "$([Environment]::GetFolderPath('MyDocuments'))" + AddLine "📂My Music" "$([Environment]::GetFolderPath('MyMusic'))" + AddLine "📂My Pictures" "$([Environment]::GetFolderPath('MyPictures'))" + AddLine "📂My Screenshots" "$([Environment]::GetFolderPath('MyPictures'))\Screenshots" + AddLine "📂My Videos" "$([Environment]::GetFolderPath('MyVideos'))" + AddLine "📂Temporary Folder" "$(GetTempDir)" + } +} + +try { + ListSpecialFolders | Format-Table -property @{e='Folder Name';width=20},'Folder Path' + exit 0 # success +} catch { + "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +} \ No newline at end of file