如何创建批处理文件以运行同一目录中的所有python文件 [英] How to create a batch file to run all python files in the same directory

查看:125
本文介绍了如何创建批处理文件以运行同一目录中的所有python文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹,其中存放用于备份特定系统的python脚本. Z:\ System管理员\系统备份\我的系统\脚本\

I have a folder where I keep my python scripts used for backing up a particular system. Z:\System Administrator\System Backups\My System\Scripts\

要开始全部运行,我想使用一个保存在同一文件夹中的.bat文件,但是我对这些文件的使用经验为零.我的阅读使我想到了这个解决方案:

To start them all going I would like to use a .bat file kept in the same folder, however I have zero experience with these files. My reading has lead me to this solution :

@echo off
start /B python "File one.py"
start /B python "It's another file.py"   

如果我以这种方式列出每个python文件,那么它将按我的意愿工作.如何运行此文件夹中显示的所有*.py文件,而不管其数字或文件名如何?

And if I list every python file in this way then it works as I would want. How can I run all *.py files that appear in this folder regardless of number or filename ?

预先感谢

推荐答案

使用以下技巧是可能的:

That's possible with the following trick:

@echo off

for %%A IN (*.py) do start /b /wait "" python "%%~fA"

注意:对于较旧的Windows版本(Windows 10之前的版本),该顺序是特定的. ,请参见此处 .

Note: For older Windows versions (pre Windows 10) the order is specific. , See here.

这篇关于如何创建批处理文件以运行同一目录中的所有python文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆