Python : get all exe files in current directory and run them?

4.8k Views Asked by At

First of all this is not homework, I'm in a desperate need for a script that will do the following, my problem is, I've never had to deal with python before so I barely know how to use it - and I need it to launch unit tests in TeamCity via a commandline build runner

What I need exactly is :

a *.bat file that will run the script

a python script that will :

  • get all *_test.exe files in the current working directory
  • run all the files which were the result of the search

Best regards

2

There are 2 best solutions below

4
On BEST ANSWER
import glob, os
def solution():
    for fn in glob.glob("*_text.exe"):
        os.startfile(fn)
1
On

If you copy this into a file, the script should do as you asked.

import os       # Access the operating system.

def solution(): # Create a function for later.
    for name in os.listdir(os.getcwd()):
        if name.lower().endswith('_test.exe'):
            os.startfile(name)

solution()      # Execute this inside the CWD.