Jump to content
Sign in to follow this  

Get path of currently selected file in Explorer?

Recommended Posts

Hey guys, hopefully you'll help me despite being new around here.

I'm trying to make a simple little script that opens the selected file in Windows Explorer with an alternate program upon pressing CTRL+Enter.

For example, I was hoping to use this to open JPEGs in Irfanview by default but open them in Photoshop when i press CTRL+Enter.

I'm unfortunately not coming up with any way to get the path of the selected file. Is there a way? Any help would be much appreciated!

Share this post

Link to post
Share on other sites

Hi, bberrry, welcome to the forum. You could always start by opening a FileOpenDialog box. That will give you the full path. Try something like this to get you started.

$var = FileOpenDialog("My File Open Test", "C:", "All (*.*)")
 MsgBox(0, "Test", $var)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post

Link to post
Share on other sites

The easiest way is to test an Explorer window is the active window. If so, send ^c to copy the selected files/folders names to the clipboard. See ClipGet() in the help. If you want to save the clipboard contents call ClipGet() before sending ^c and ClipPut() to restore after you copy files out. If multiple files/folders are selected the paths will be separated by a LF character.

Here's a starting point detecting that the active window is an Explorer window. Explorer uses one of two class names. So you need to test for both. See SetHotKey() in the help for setting a function to fire when Control-Enter is pressed.

Func GetExplorerSelection()
Local $saveClip = ""
Local $filesFolders = ""
Local $handle = _WinAPI_GetForegroundWindow()
Local $className = _WinAPI_GetClassName($handle)
If $className = "ExploreWClass" Or $className = "CabinetWClass" Then
$saveClip = ClipGet()
Sleep(50) ; give clipboard time to react
$filesFolders = ClipGet()
; test if $filesFolders contains @LF and split if so etc..
; code to call StringSplit() etc..
Edited by MilesAhead

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...