是否可以定义一个目录列表,如“dir1”,“dir2” ,然后为每个目录执行一些操作,例如:
xcopy C:\test\*.dll D:\%%le_dir%%\dll /Y
xcopy C:\test\*.exe D:\%%le_dir%%\exe /Y
其中le_dir
是定义列表中的一个目录
试试这个(列表是在一个文本文件中):
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:“)”添加。