Created
December 23, 2023 09:33
-
-
Save 1208nn/82b84069cda968ad0921ea4ba2011912 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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