0

I need a command BACH to allow me to run a file to multiple folders . This executable file is already copied these folders.

for /D %i in (C:\Teste\*) do Paint.bat %i

The above command did so, however , he runs paint.bat contained in the folder " test " FOR the other subfolders , not what 's right .

Subfolders already contains a copy of paint.bat . I need a command to execute each of these copies . It's the same file , however , it needs to be run within each folder .

Jones
  • 7
  • 4

2 Answers2

0

Your code does not switch the work folder, your code calls the Bat-file from one place always. Try this

for /D %i in (C:\Teste\*) do pushd .&cd "%i"&call Paint.bat %i&popd

Now I cannot check this, but I think it works so:

  • remember current folder in stack (pushd .)
  • switch current folder to the value of %i
  • execute Paint.Bat (it must be placed in each subfolder)
  • restore current folder from stack (popd)

This script is not recursive, only subfolders will be walked. Excuse my English.

Solo.dmitry
  • 690
  • 8
  • 15
  • Excelente...but... How can I prevent it performs the function for folders which have been executed ? If I create a new folder within the ' test ' their function is performed again in all folders . I wish it were only performed on each new folder added in ' Test ' – Jones Nov 07 '14 at 19:42
  • The simplest way is delete script (add del /Q Paint.bat after CALL). Then the call of it will be failed. – Solo.dmitry Nov 09 '14 at 11:32
0

Erm... Am i right with:

FOR /D %I IN ("Anyfolder\*") DO 

: %I will be the Fullqualified Path to each subfolder in "Anyfolder" (not any deeper). You want to execute the file "paint.bat" which is located in each folder - and paint.bat should be startet with the fullqualified path to that folder it's in?

So isn't it just:

FOR /D %I IN ("Anyfolder\*") DO "%~I\paint.bat" "%~I"

? Maybe you must specify a Start before:

FOR /D %I IN ("Anyfolder\*") DO START "" "%~I\paint.bat" "%~I"

(Start sometimes makes trouble when not doublequoting - or setting - a windowtitle.)

BaBa
  • 337
  • 2
  • 10