Get the Selected Files From the Active Explorer Tab in AutoHotkey v2

Want your script to act on the files you have selected in File Explorer?

That used to be easy. Then Windows 11 gave Explorer tabs, and a lot of the old code started grabbing files from the wrong tab.

Explorer_GetSelection is an AutoHotkey v2 function that gets it right. It returns the full paths of the selected files from the tab you’re actually looking at. 😊

Get Explorer Selection: AutoHotkey v2 library that returns the selected files in File Explorer

One Call Returns the Full Paths


Include the file, then call the function while Explorer is the active window:

#Include Get Explorer Selection V2.ahk
F1::MsgBox Explorer_GetSelection()              ; one path per line
Files := Explorer_GetSelection(, "array")  ; or an Array to loop over

You pick the shape of the answer:

  • Text (the default): every selected path, one per line
  • Array: pass “array” and loop over the paths with a for loop
  • Nothing selected: you get an empty result, so a simple if check works

Built for Windows 11 Explorer Tabs


One Explorer window can now hold several tabs, each showing a different folder. Code that just asks “which Explorer window?” can return the wrong tab.

This function finds the tab that’s showing right now and reads the selection from that one. The tab-matching code comes from Lexikos, the lead developer of AutoHotkey.

Not in Explorer? If another program is active, you get a short “Nothing was Selected” tip and an empty result. No errors to trap.

What You Can Build With It


Pair it with a hotkey and you can do almost anything to the files you just selected:

  • Copy the paths to the clipboard for an email or a chat
  • Open the files in a specific program
  • Rename, move or zip them with your own script

By default it reads the active window. You can also pass a window handle if you want a specific Explorer window.

What’s in the Download


  • Get Explorer Selection V2.ahk: the function plus its tab helper, one file, no other libraries

Including the file doesn’t run anything. Nothing happens until you call the function.

Requirements: Windows and AutoHotkey v2. Works with tabbed Explorer in Windows 11 and with Windows 10 Explorer.

Get Explorer_GetSelection


Explorer_GetSelection is $4.99. Drop it in your lib folder and it’s ready whenever a script needs your selected files.

Small function, and it ends the wrong-tab problem for good. ⚡

Joe

Comments are closed.