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"
}
function AddLine { param([string]$FolderName, [string]$FolderPath)
if (Test-Path "$FolderPath" -pathType container) {
New-Object PSObject -property @{ 'Folder Name' = "$FolderName"; 'Folder Path' = "📂$FolderPath" }
function TryFolder([string]$name, [string]$path) {
if (Test-Path "$path" -pathType container) {
New-Object PSObject -property @{ 'Folder Name' = "$name"; 'Folder Path' = "📂$path" }
}
}
function ListSpecialFolders {
if ($IsLinux) {
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)"
TryFolder "Boot files" "/boot"
TryFolder "Config files" "/etc"
TryFolder "Desktop" "$HOME/Desktop"
TryFolder "Device files" "/dev"
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 "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/.."
AddLine "Users" "$Path/"
AddLine "Videos" "$HOME/Videos/"
TryFolder "Users" "$Path"
TryFolder "Videos" "$HOME/Videos"
} else {
$FolderNames = [System.Enum]::GetNames('System.Environment+SpecialFolder')
$FolderNames | Sort-Object | ForEach-Object {
if ($Path = [System.Environment]::GetFolderPath($_)) {
AddLine "$_" "$Path"
TryFolder "$_" "$Path"
}
}
AddLine "Repositories" "$HOME\source\repos"
AddLine "SSH" "$HOME\.ssh"
AddLine "Temporary" "$(GetTempDir)"
TryFolder "Repositories" "$HOME\source\repos"
TryFolder "SSH" "$HOME\.ssh"
TryFolder "Temporary" "$(GetTempDir)"
$Path = Resolve-Path "$HOME/.."
AddLine "Users" "$Path"
TryFolder "Users" "$Path"
}
}
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
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"