Python:获取当前目录中的所有exe文件并运行它们?

发布于 2024-09-05 11:29:25 字数 262 浏览 3 评论 0原文

首先,这不是家庭作业,我迫切需要一个能够执行以下操作的脚本,我的问题是,我以前从未处理过 python,所以我几乎不知道如何使用它 - 而且我需要它通过命令行构建运行程序在 TeamCity 中启动单元测试

我真正需要的是:

一个 *.bat 文件,将运行脚本

一个 python 脚本,将:

  • 获取当前工作目录中的所有 *_test.exe 文件
  • 运行所有文件这是搜索的结果

最好的问候

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

入画浅相思 2024-09-12 11:29:25
import glob, os
def solution():
    for fn in glob.glob("*_text.exe"):
        os.startfile(fn)
import glob, os
def solution():
    for fn in glob.glob("*_text.exe"):
        os.startfile(fn)
御弟哥哥 2024-09-12 11:29:25

如果您将其复制到文件中,脚本应该按照您的要求执行。

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.

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文