I need a Window CMD to loop through folders in a directory and execute a command on each one

Normally I would have to call a command once per folder like this:

processdata.cmd C:\data\10-2-2019-run1

processdata.cmd C:\data\10-2-2019-run2

processdata.cmd C:\data\10-2-2019-run3

etc.

I want to write a for loop that will run that command once per folder and append the directory just like in the commands above

I don't want it to loop through sub-folders

The only folders there contain data, so I don't need it to exclude any folders or files.

Just a very simple For loop using windows CMD (preferably not powershell)

How can I do this?

Thanks,

2 Answers

Try this.

for /D %G in ("c:\data\*") do processdata.cmd "%~fG"

4

Normally I would have to call a command once per folder like this:

processdata.cmd C:\data\10-2-2019-run1

processdata.cmd C:\data\10-2-2019-run2

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like