python open directory in file explorer code example
Example 1: open choose files from file explorer python
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
files = filedialog.askopenfilenames()
Example 2: how to open file explorer in python
import os
import subprocess
FILEBROWSER_PATH = os.path.join(os.getenv('WINDIR'), 'explorer.exe')
def explore(path):
path = os.path.normpath(path)
if os.path.isdir(path):
subprocess.run([FILEBROWSER_PATH, path])
elif os.path.isfile(path):
subprocess.run([FILEBROWSER_PATH, '/select,', os.path.normpath(path)])
Example 3: python open file from explorer
import sys
path = r'C:\Program Files (x86)\IronPython 2.7\Lib'
sys.path.append(path)
import subprocess
subprocess.Popen('explorer "C:\temp"')