Jump to content
Sign in to follow this  
bberrry

Get path of currently selected file in Explorer?

Recommended Posts

bberrry

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
JLogan3o13

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)

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
MilesAhead

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()
Send("^c")
Sleep(50) ; give clipboard time to react
$filesFolders = ClipGet()
ClipPut($saveClip)
; test if $filesFolders contains @LF and split if so etc..
; code to call StringSplit() etc..
EndIf
EndFunc
Edited by MilesAhead

Share this post


Link to post
Share on other sites
bberrry

Ah, I didn't think to use clipboard :) Thank you for your help

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  

×