0

Using subprocess I want to open Windows File Explorer. Then wait for 1 second and close it:

import subprocess, time
subprocess.Popen(r'explorer /select,"D:\tmp\temp"')
time.sleep(1)

How to close File Explorer?

alphanumeric
  • 17,967
  • 64
  • 244
  • 392

1 Answers1

0

I hope it works

import subprocess
import time
from pygetwindow import getWindowsWithTitle
from pywinauto import Application
# Open
subprocess.Popen(r'explorer /select,"D:\tmp\temp"')
time.sleep(1)
#locate window
explorer_windows = getWindowsWithTitle("This PC")
time.sleep(1)
# Close the window 
window = explorer_windows[0]
app = Application().connect(handle=window._hWnd)
app.top_window().close() 
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103