Xlaudius
Xlaudius

Reputation: 1837

For loop with multi-line body

Is it possible to define a list of directories e.g. "dir1", "dir2" and then for each of those directories execute a couple of actions, eg:

Upvotes: 1

Views: 435

Answers (1)

Endoro
Endoro

Reputation: 37569

Try this (the list is in a text file):

for /f "delims=" %%i in (list.txt) do (
xcopy "C:\test\*.exe" "D:\%%i\exe" /Y
xcopy "C:\test\*.dll" "D:\%%i\dll" /Y
)

Put the destination folders in a text file list.txt:

dir1
dir2
...

Edit1 (folders are defined in the script):

set "folders=dir1 dir2 dir3"
for %%i in (%folders%) do (
xcopy "C:\test\*.exe" "D:\%%i\exe" /Y
xcopy "C:\test\*.dll" "D:\%%i\dll" /Y
)

Edit2 (if there are spaces in folder names):

set "folders="dir 1" "dir 2" "dir 3""
for %%i in (%folders%) do (
xcopy "C:\test\*.exe" "D:\%%~i\exe" /Y
xcopy "C:\test\*.dll" "D:\%%~i\dll" /Y
)

Edit3: ")" added.

Upvotes: 4

Related Questions