Reputation: 3
I want to create a python (I'm using 3.6.2 although if there's a solution on a newer version I'd be happy to update) program that randomly selects a game from a list of game titles and runs the .exe for the game. However, I don't know how to run a .exe file from a specific folder location ie C:Program Files
Upvotes: 0
Views: 622
Reputation: 656
Basically what you need to do is:
(You need to import glob, random and os
)
file_list = glob.glob("path/to/folder/*.exe")
game = random.choice(file_list)
os.startfile(game)
So:
import glob
import random
import os
file_list = glob.glob("path/to/folder/*.exe")
game = random.choice(file_list)
os.startfile(game)
Upvotes: 1