How to copy the full path containing the file name to the clipboard using shortcut
How to copy the full path containing the file name to the clipboard using shortcut
You can use the win32clipboard module .me.uk / pywin32-docs / contents.html "> PyWin32 (Most likely you already have it installed). The GetClipboardData () function (which is usually used for text) accepts a format specification parameter from the clipboard, in which case you can pass the value constant 15 (CF_HDROP) used to move / copy files by CTR + C and CTR + V by Windows. I've done a brief get_path_of_file_on_clipboard function to illustrate:
from win32clipboard import OpenClipboard, GetClipboardData, CloseClipboard
def get_path_of_file_on_clipboard():
CF_HDROP = 15
OpenClipboard()
data = "No file was selected."
try:
data = GetClipboardData(CF_HDROP)
except TypeError:
print("ERROR: You must copy a FILE to the clipboard.")
finally:
CloseClipboard()
return data
print(get_path_of_file_on_clipboard())
This function returns a string with the absolute path to the file that was passed to the clipboard (with CTR + C). Once you have obtained this path, simply adapt to your application with Tkinter (Just capture the CTR + V event and insert this string wherever you want).