How to make it go through certain folders(ex. 1-8 on the 开发者_如何学Cdrive E:) and their trees and copy them on F: in the batch file(my doesn't work):
set drive=E:
for %%a in (1,2,3,4,5,6,7,8) do (
set folder=%%a
for /R "%drive%\%%a" %%b in (*) do (
copy "%%b" %drive%\%folder%
I think the syntax you want is
for %%F in (1 2 3 4 5 6 7 8) do (
xcopy /e e:\%%F f:\
)
You're trying to set and reuse an environment variable in a loop. This cannot work since cmd
expands all environment variables when parsing a command, not when running it. So you need to enable delayed expansion:
setlocal enabledelayedexpansion
set drive=E:
for %%a in (1,2,3,4,5,6,7,8) do (
set folder=%%a
for /R "%drive%\%%a" %%b in (*) do (
copy "%%b" %drive%\!folder!
)
)
(you were also missing a few closing parenthesis, I added those for you)
But you could just as well use %%a
. It should still exist in the inner loop ...
set drive=E:
for %%a in (1,2,3,4,5,6,7,8) do (
for /R "%drive%\%%a" %%b in (*) do (
copy "%%b" %drive%\%%a
)
)
精彩评论