In Python, how do I jump to a file in the Windows Explorer? I found a solution for jumping to folders:
but I have no solution for files.
From Geoff Chappell’s The Windows Explorer Command Line
How to Open EXP Files. Since EXP files are associated with more than ten programs and applications, double click on the file to see if it will automatically open in a default program you have installed on your PC. EXP files can consist of different file types, so you may already have a program which will open the file. To get This PC to display when you launch File Explorer, open the app and click the 'View' tab on the ribbon. Garrys mod free 2019. Click the 'Options' button to open the File Explorer Options window. In the 'Open 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 and this solution may help other people.
For some reason, on windows 7 it always opens the users Path, for me following worked out:
Alternatively, you could use the fileopenbox module of EasyGUI to open the file explorer for the user to click through and then select a file (returning the full filepath).
As explorer could be overridden it would be a little safer to point to the executable directly. (just had to be schooled on this too)
And while you’re at it: use Python 3s current subprocess API: run()
For anyone wondering how to use a variable in place of a direct file path. The code below will open explorer and highlight the file specified.
The code below will just open the specified folder in explorer without highlighting any specific file.