Update list-special-folders.ps1

This commit is contained in:
Markus Fleschutz 2023-10-05 20:50:49 +02:00
parent 601b8411e0
commit fb00ef93fe

View File

@ -23,49 +23,58 @@ function GetTempDir {
return "C:\Temp" return "C:\Temp"
} }
function AddLine { param([string]$FolderName, [string]$FolderPath) function TryFolder([string]$name, [string]$path) {
if (Test-Path "$FolderPath" -pathType container) { if (Test-Path "$path" -pathType container) {
New-Object PSObject -property @{ 'Folder Name' = "$FolderName"; 'Folder Path' = "📂$FolderPath" } New-Object PSObject -property @{ 'Folder Name' = "$name"; 'Folder Path' = "📂$path" }
} }
} }
function ListSpecialFolders { function ListSpecialFolders {
if ($IsLinux) { if ($IsLinux) {
AddLine "Desktop" "$HOME/Desktop/" TryFolder "Boot files" "/boot"
AddLine "Documents" "$HOME/Documents/" TryFolder "Config files" "/etc"
AddLine "Downloads" "$HOME/Downloads/" TryFolder "Desktop" "$HOME/Desktop"
AddLine "Dropbox" "$HOME/Dropbox/" TryFolder "Device files" "/dev"
AddLine "Home" "$HOME/" TryFolder "Documents" "$HOME/Documents"
AddLine "Music" "$HOME/Music/" TryFolder "Downloads" "$HOME/Downloads"
AddLine "Pictures" "$HOME/Pictures/" TryFolder "Dropbox" "$HOME/Dropbox"
AddLine "Repositories" "$HOME/Repos/" TryFolder "Home" "$HOME"
AddLine "Repositories" "$HOME/Repositories/" TryFolder "Mount points" "/mnt"
AddLine "Screenshots" "$HOME/Pictures/Screenshots/" TryFolder "Music" "$HOME/Music"
AddLine "Snap" "$HOME/snap/" TryFolder "Optional packages" "/opt"
AddLine "SSH" "$HOME/.ssh/" TryFolder "Pictures" "$HOME/Pictures"
AddLine "Trash" "$HOME/.local/share/Trash/" TryFolder "Recovered files" "/lost+found"
AddLine "Templates" "$Home/Templates/" TryFolder "Removable media" "/media"
AddLine "Temporary" "$(GetTempDir)" TryFolder "Repositories" "$HOME/Repos"
TryFolder "Repositories" "$HOME/Repositories"
TryFolder "Root" "/"
TryFolder "Screenshots" "$HOME/Pictures/Screenshots"
TryFolder "Snap" "$HOME/snap"
TryFolder "SSH" "$HOME/.ssh"
TryFolder "System binaries" "/sbin"
TryFolder "Trash" "$HOME/.local/share/Trash"
TryFolder "Templates" "$Home/Templates"
TryFolder "Temporary" "$(GetTempDir)"
$Path = Resolve-Path "$HOME/.." $Path = Resolve-Path "$HOME/.."
AddLine "Users" "$Path/" TryFolder "Users" "$Path"
AddLine "Videos" "$HOME/Videos/" TryFolder "Videos" "$HOME/Videos"
} else { } else {
$FolderNames = [System.Enum]::GetNames('System.Environment+SpecialFolder') $FolderNames = [System.Enum]::GetNames('System.Environment+SpecialFolder')
$FolderNames | Sort-Object | ForEach-Object { $FolderNames | Sort-Object | ForEach-Object {
if ($Path = [System.Environment]::GetFolderPath($_)) { if ($Path = [System.Environment]::GetFolderPath($_)) {
AddLine "$_" "$Path" TryFolder "$_" "$Path"
} }
} }
AddLine "Repositories" "$HOME\source\repos" TryFolder "Repositories" "$HOME\source\repos"
AddLine "SSH" "$HOME\.ssh" TryFolder "SSH" "$HOME\.ssh"
AddLine "Temporary" "$(GetTempDir)" TryFolder "Temporary" "$(GetTempDir)"
$Path = Resolve-Path "$HOME/.." $Path = Resolve-Path "$HOME/.."
AddLine "Users" "$Path" TryFolder "Users" "$Path"
} }
} }
try { try {
ListSpecialFolders | Format-Table -property @{e='Folder Name';width=18},'Folder Path' ListSpecialFolders | Format-Table -property @{e='Folder Name';width=19},'Folder Path'
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"