Sometimes we may need to copy a file or folder path from your email or chat window to the clipboard, and open the file or folder manually. Most people open the file or folder by launching the Run dialog, pasting the path from the Clipboard, and clicking OK.
If your job involves doing this sort of task repeatedly, manually opening the Run dialog and pasting the path every time can be tedious. You can simplify this using a keyboard shortcut (hotkey) with the help of a small AutoHotKey (AHK) script.
How to Open the File or Folder Path from the Clipboard
The AHK script mentioned below reads the file or folder path saved in the clipboard, checks if the path is valid and if so, launches it.
AutoHotkey is a free, open-source scripting language for Windows that allows users to easily create small to complex scripts for all kinds of tasks such as form fillers, auto-clicking, macros, etc.
- Download AutoHotkey and install it.
- Right-click on the desktop, click New, and select AutoHotkey Script.
- Rename the script file
New AutoHotkey Script.ahk
toopen_path_clipboard.ahk
- Right-click the file and choose Edit Script
- Remove all lines in the script and replace it with the following code:
^+o::openpathfromclipboard() openpathfromclipboard() { strpath = %Clipboard% strpath := StrReplace(strpath,"""") strpath := StrReplace(strpath,"'") If InStr(strpath, "%") { Transform, strpath, Deref, %strpath% } If FileExist(strpath) { Run, % strpath } }
- Save the file
open_path_clipboard.ahk
and close the editor. - Double-click to run the script. It will show up in the notification area.
- Now, copy a file or folder path from your chat window, Command Prompt, or elsewhere to the Clipboard.
The path can be to a file or folder, and it can be in any of the formats listed below:C:\Windows\System32 "C:\Windows" %AppData% %userprofile%\desktop '%systemroot%\system32' "%systemroot%\notepad.exe" C:\Windows\system32\cmd.exe
- Press Ctrl + Shift + o to launch the file or folder path stored on the Windows Clipboard. The file/folder will be launched in the same way as you launch it via the Run dialog or double-click on the item. If the path is a folder, it should open in File Explorer.
Script Customization
You can change the keyboard hotkey in the (1st line of the) script if you need it. Here are the modifiers.
!
{Alt}+
{Shift}^
{Ctrl}#
{Winkey}
For example, for Ctrl + Alt + Shift + O, you’d use ^!+o
.
(For the full list of keys that you can send or intercept, see AutoHotkey SendInput documentation.)
Other AutoHotKey scripts
We’ve covered some AutoHotKey scripts before. Here are some samples:
- Clear Recent Files history Using Script in Windows 10
- Insert Date/Time in Any Program Using Keyboard Hotkey
- How to Change WinKey + E Shortcut Target in Windows 10
- How to Make Snipping Tool Default to New Snip when Launched
- Clear all notifications in Action Center using Keyboard or Shortcut
- Open Command Prompt in Current Folder Using Keyboard Shortcut
- How to run Batch files invisibly, without displaying Command Prompt
- Photos App Mouse Wheel Settings: Scroll to Zoom or View Prev/Next
Hope that helped you quickly open a file or folder path stored on the clipboard.
One small request: If you liked this post, please share this?
One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:- Pin it!
- Share it to your favorite blog + Facebook, Reddit
- Tweet it!
I have a file path with a command-line option, like so:
C:\Daily\MyProgram.exe /open C:\Daily\Folder\Subfolder\file.html
This file path opens perfectly when pasted into the Run dialog. It does not, however, open via your script. My file path appears to fall outside your list of acceptable formats. Is there a way to modify the script to accommodate my kind of path? Thanks.
John, Try this:
But it won’t validate if the file exists or not. Will try to execute anything from the clipboard.