Skip to main content
 首页 » 编程设计

python之批处理文件 : Run command for every file of certain extension

2024年11月01日10jackei

我运行一个 python 命令

python file.py inputfile.STL

但我想将其扩展为一次输入多个文件。我将如何制作一个 Windows 批处理文件,该文件在运行时将为该目录中的每个 *.STL 文件运行一个命令。因此,例如它将运行,

python file.py INPUTFILE1.stl 
python file.py ANOTHERFILE.stl 
python file.py BLAH.stl 
.... 

请注意,.STL 文件将具有不同的前缀。

请您参考如下方法:

这些主题可以提供帮助:Batch script loop和 batch file Copy files with certain extensions from multiple directories into one directory

所以基本上:

for %f in (*.stl) do python file.py %f 

这将创建一个循环,执行目录中所有扩展名为 .STL 的文件。