Shortcut to copy path of selected file in Explorer Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
JohnTravolski
Posts: 8
Joined: 22 Dec 2015, 15:10

Shortcut to copy path of selected file in Explorer

10 Jul 2018, 02:16

I'm not sure if this is possible, but I'm wondering if AutoHotKey can be used to create a keyboard shortcut that, when inside File Explorer, copies the path of the highlighted item to the clipboard if a file or folder is selected, and copies the path to the current folder being browsed in if nothing is selected. I've done some research, and it seems like something along those lines can be done, as seen here, but unfortunately I don't really understand it:

https://autohotkey.com/board/topic/6072 ... ile/page-2

For example, if I'm at the following directory in File Explorer (C:\Expedited\Scripts\AutoHotKey) and I have the item "OpenWith.ahk" selected (highlighted in blue in File Explorer), then the text "C:\Expedited\Scripts\AutoHotKey\OpenWith.ahk" should be copied to the clipboard. If no item was selected, then just the text "C:\Expedited\Scripts\AutoHotKey" should be copied.

However, I'm a relatively new user and I don't quite understand how it works. With something like this being pretty useful to just about anybody, I also wouldn't be surprised if a script like this has already been written by somebody out there. Do you know of such a script? If not, can it be done in AutoHotKey?
Guest

Re: Shortcut to copy path of selected file in Explorer

10 Jul 2018, 05:17

Simply sending ^c will copy the path of the selected file(s) to the clipboard as text which you can simply access using the Clipboard variable.

See https://autohotkey.com/docs/misc/Clipboard.htm - second paragraph.

Various techniques here https://autohotkey.com/boards/viewtopic.php?t=11297 incl clipboard but also using COM (similar to what you've linked too) - try several, choose the one that work for you :-)
User avatar
jeeswg
Posts: 4578
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Shortcut to copy path of selected file in Explorer  Topic is solved

13 Jul 2018, 07:39

- There is always one item (file/folder) that is focused. The item is either selected (highlighted blue) or it is not selected.
- I would suppose that the best approach would be to retrieve the path of the focused item if it is selected, or otherwise, to retrieve the path of the folder if the focused item is not selected.
- In the script I've made it so that the script sends Ctrl+C when the main Explorer control (DirectUIHWND3) is not focused.
- It's easy to retrieve the focused item using a COM object, but AFAIK it is not so easy to get an 'IsSelected' state for that item. The script compares the name of the focused item against all selected items to determine if it is selected. Cheers.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

- Link:
FolderItem object | Microsoft Docs
https://docs.microsoft.com/en-gb/windows/desktop/shell/folderitem
JohnTravolski2

Re: Shortcut to copy path of selected file in Explorer

14 Jul 2018, 01:40

jeeswg wrote:- There is always one item (file/folder) that is focused. The item is either selected (highlighted blue) or it is not selected.
- I would suppose that the best approach would be to retrieve the path of the focused item if it is selected, or otherwise, to retrieve the path of the folder if the focused item is not selected.
- In the script I've made it so that the script sends Ctrl+C when the main Explorer control (DirectUIHWND3) is not focused.
- It's easy to retrieve the focused item using a COM object, but AFAIK it is not so easy to get an 'IsSelected' state for that item. The script compares the name of the focused item against all selected items to determine if it is selected. Cheers.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

- Link:
FolderItem object | Microsoft Docs
https://docs.microsoft.com/en-gb/windows/desktop/shell/folderitem



This functions perfectly, thank you very much!

Return to “Ask For Help”

Who is online

Users browsing this forum: simonk and 50 guests