Skip to content

Go-Desktop

Sets the working directory to the user's desktop folder

param([string]$path = "")

try {
	if ($path -eq "") {
		if ($IsLinux -or $IsMacOS) {
			if (-not(Test-Path "~/Desktop" -pathType container)) {
				throw "No 'Desktop' folder in your home directory yet"
			}
			$path = Resolve-Path "~/Desktop"
		} else {
			$path = [Environment]::GetFolderPath('DesktopDirectory')
			if (-not(Test-Path "$path" -pathType container)) {
				throw "Desktop folder at $path does not exist yet"
			}
		}
	}
	Set-Location "$path"
	$files = Get-ChildItem $path -attributes !Directory
	$folders = Get-ChildItem $path -attributes Directory
	"??$path entered (has $($files.Count) files and $($folders.Count) folders)"
	exit 0 # success
} catch {
	"?? ERROR: $($Error[0])"
	exit 1
}

An interactive directory of PowerShell scripts.