用于多线体的循环

时间:2013-03-16 16:09:13

标签: windows for-loop batch-file cmd

是否可以定义目录列表,例如“dir1”,“dir2”然后为每个目录执行一些操作,例如:

  • xcopy C:\test\*.dll D:\%%le_dir%%\dll /Y

  • xcopy C:\test\*.exe D:\%%le_dir%%\exe /Y

  • 其中le_dir是定义列表中的目录

1 个答案:

答案 0 :(得分:4)

试试这个(列表在文本文件中):

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

将目标文件夹放在文本文件list.txt中:

dir1
dir2
...

Edit1(文件夹在脚本中定义):

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(如果文件夹名称中有空格):

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:“)”已添加。