Jonathan Kirshner
Jonathan Kirshner

Reputation: 11

Finding the location of a program/file Python

Here is my code to find the name of the active window. I now need to be able to find the location of the program.

 import win32gui
 window = win32gui.GetForegroundWindow()
 active_window_name = win32gui.GetWindowText(window)
 print(active_window_name)

How do i find the location of the program and file using either the name or anything else with out manually inputting the name.

Upvotes: 0

Views: 1648

Answers (1)

catsock
catsock

Reputation: 1851

I'm assuming you want to find the location of the file as in the directory path. There's multiple ways to do this, and the easiest one looks like this:

import os 
dir_path = os.path.dirname(os.path.realpath(__file__))

Upvotes: 2

Related Questions