Skip to content

Instantly share code, notes, and snippets.

@1208nn
Created December 23, 2023 09:33
Show Gist options
  • Save 1208nn/82b84069cda968ad0921ea4ba2011912 to your computer and use it in GitHub Desktop.
Save 1208nn/82b84069cda968ad0921ea4ba2011912 to your computer and use it in GitHub Desktop.
function cdp {
$shell = New-Object -ComObject Shell.Application
$windows = $shell.Windows() | Where-Object { $_.FullName -eq 'C:\Windows\explorer.exe' && $_.LocationURL -match 'file:///' }
if ($windows.Count -eq 0) {
Write-Host "No window found"
return
}
$selectedWindow = if ($windows.Count -eq 1) {
$windows
}
else {
$windows | Select-Object -Property LocationName, LocationURL | Out-GridView -PassThru -Title "Select a path"
}
if ($selectedWindow) {
$path = $selectedWindow.LocationURL -replace 'file:///', '' -replace '/', '\'
$path = [System.Uri]::UnescapeDataString($path)
try {
$localPath = [System.Uri]::new($path).LocalPath
Set-Location $localPath
}
catch {
Write-Host "Failed to set location: $path"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment