Skip to content

cd-desktop

Sets the working directory to the user's desktop folder

#requires -version 5.1

try {
	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
} catch {
throw
}

This script has no configurable parameters.

An interactive directory of PowerShell scripts.