Python get filepath
You are right, to add something in windows context menu, you will need to edit the windows registry editor.
To copy filelocation in clipboard, you can use pyperclip
but this can be done using only tkinter
:
from tkinter import Tk, filedialogr = Tk()r.withdraw()filename = filedialog.askopenfilename()#print(filename)r.clipboard_clear()r.clipboard_append(filename)r.update() # now it stays on the clipboard after the window is closedr.destroy()
What you can do is, when in file explorer, you right-click, then in the context menu, there will be an option (such as, "copy the file location of a file") which you can add using registry editor. Then on clicking that option, another file dialog
is opened, in which the location of whichever file you select is then copied to your clipboard.
EDIT: To only add a "Copy Path" option in the context menu:
In registry editor, for files, in HKEY_CLASSES_ROOT\*\shell\Copy Path\command
, and for folders, in HKEY_CLASSES_ROOT\Directory\shell\Copy Path\command
, add the following command by setting the value of (Default) to
cmd.exe /c (echo.|set /p=%1) | clip
That's it, without python, using only the default command line interpreter, you can copy the full path of file/folders in windows.