Open explorer on a file
In Python, how do I jump to a file in the Windows Explorer? I found a solution for jumping to folders:
import subprocess
subprocess.Popen('explorer "C:\path\of\folder"')
but I have no solution for files.
From Geoff Chappell's The Windows Explorer Command Line
import subprocess
subprocess.Popen(r'explorer /select,"C:\path\of\folder\file"')
A nicer and safer solution (only in Windows unfortunately) is os.startfile().
When it's given a folder instead of a file, it will open Explorer.
Im aware that i do not completely answer the question since its not selecting a file, but using subprocess
is always kind of a bad idea (for security reasons) and this solution may help other people.