Home > Software design >  How do you find Discord.exe using python?
How do you find Discord.exe using python?

Time:10-27

I'm trying to find the Discord.exe using python so I can start it automatically, the problem is the only solutions I've found is to get the full path, which it changes quite a bit, meaning I'd have to update my code every single time Discord updates.

CodePudding user response:

Navigate to the discord root folder, which is constant, in windows it'll be something like C:\Users\your_name\AppData\Local\Discord, than you can use os.walk("."), it'll return a generator to all the folders down the folder tree, so you can convert this into a list using list(os.walk(".")), as yo only want the folders on your current locantion you use the 0th index of this list, and as you want the folders you'll get the second index, the result will be this list(os.walk("."))[0][1], now you just need to find the folder that the executable is located which is called "app-version", so we can do a simple iteration to grab this folder, in the and the code will be something like:

#code to reach root folder
folders = list(os.walk("."))[0][1]
folder = ""
for f in folders:
    if f[:3] == "app":
        folder = f
#navigate to folder and execute the Discord.exe
  • Related