开发者

Batch Scripting: Running python script on all directories in a folder

开发者 https://www.devze.com 2023-04-08 21:00 出处:网络
I have a python script called script.py which I would like to run on all of the directories inside of a specific directory. What is the easiest way to do this using batch scripting?

I have a python script called script.py which I would like to run on all of the directories inside of a specific directory. What is the easiest way to do this using batch scripting?

My assumption is some usage o开发者_JS百科f the FOR command, but I can't quite make any leads to solve the problem using the command...


Use the /d operator on for:

for /D %%d in (*) do script.py %%d

This assumes you only need to execute one command per directory (script.py %%d) if you need to execute more use braces (). Also I'm guessing there's an execution engine needed first, but not sure what it is for you.

A multi-line example:

for /D %%d in (%1) do (
   echo processing %%d
   script.py %%d
)


Building upon Rudu's answer, and assuming script.py is located in the same directory (say C:\Test) as the following batch script, you could also run script.py recursively on all the directories present in C:\Test:

@echo off
for /d /r %%d in (*) do (
  echo Processing: %%d
  script.py "%%d"
)

The FOR help available from cmd.exe does not seem to mention it supports multiple modifiers, but it works on Windows 7.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号