用于多线体的循环

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

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

 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 ... 

编辑1(文件夹在脚本中定义):

 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 ) 

编辑2(如果文件夹名称中有空格):

 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 ) 

编辑3:“)”添加。