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.
精彩评论