Get path of focused explorer window #1131
Replies: 4 comments 1 reply
-
|
Hi there! I just asked AI and it came up with this powershell script which seems to be working! On my system, it prints the directory of the currently focused explorer window. I guess that you could use this as a starting point to create your script! Add-Type @"
using System;
using System.Runtime.InteropServices;
public class GetForegroundWindowPath {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
}
"@
# Initialize the variable before using [ref]
$procId = 0
# Get handle and process ID of the foreground window
$hWnd = [GetForegroundWindowPath]::GetForegroundWindow()
$null = [GetForegroundWindowPath]::GetWindowThreadProcessId($hWnd, [ref]$procId)
# Check if it's an Explorer process
if ($procId) {
$process = Get-Process -Id $procId -ErrorAction SilentlyContinue
if ($process -and $process.ProcessName -eq 'explorer') {
$shell = New-Object -ComObject Shell.Application
foreach ($window in $shell.Windows()) {
try {
if ($window.HWND -eq [int64]$hWnd) {
# Output the folder path
$window.Document.Folder.Self.Path
return
}
} catch {}
}
} else {
Write-Host "Foreground window is not File Explorer."
}
} else {
Write-Host "No foreground window found."
} |
Beta Was this translation helpful? Give feedback.
-
|
It doesn't work for me! plus I don't see the everything software path in your code. Could you explain me step by step how you made it work with kando ? Thank you! |
Beta Was this translation helpful? Give feedback.
-
|
Everything is a powerfull and light search engine that you can use instead of the default windows search! Nonetheless, thanks for the starting point. I'll come back with the solution if I manage to make it work! Have a good day! |
Beta Was this translation helpful? Give feedback.
-
|
I suggest you to start Using XYplorer. It supports scripts, shortcuts and macros which can be launched via Kando items. E.g. you can emulate shortcut or execute CLI command: There's Everything script which can search for files relative to the current path. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I use Everything as search engine instead of the default windows one and it's on top!
I would like to have an icon in my kando circle when I'm in the file explorer, in a specific folder like everything does with the context menu :
when you open everyting with the context menu, it open everyting window with the path of that specific folder instead of the generic windows with just "C:".
It would have worked like a charm in kando if there was a shortcut to do that, unfortunately, this is only available with the right click!
there is a shortcut menu in everything that allow you to "new window", "display window" or "comute windows", but all 3 of them just display the default path window, not the current path window...
Is there any way I could make it work with kando? maybe with a powershell script? I tried different things but it either open everything blank or the default kando folder...
Beta Was this translation helpful? Give feedback.
All reactions