如何使用批處理文件將多個文件夾復制到另一個路徑?

[英]How do I copy multiple folders to another path with a batch file?


How to make it go through certain folders(ex. 1-8 on the drive E:) and their trees and copy them on F: in the batch file(my doesn't work):

如何讓它通過某些文件夾(例如驅​​動器E :)上的1-8和它們的樹並將它們復制到F:批處理文件中(我的工作不正常):

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% 

2 个解决方案

#1


0  

I think the syntax you want is

我認為你想要的語法是

for %%F in (1 2 3 4 5 6 7 8) do (
    xcopy /e e:\%%F  f:\
)

#2


0  

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:

您正在嘗試在循環中設置和重用環境變量。這不起作用,因為cmd在解析命令時擴展所有環境變量,而不是在運行它時。所以你需要啟用延遲擴展:

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

但你也可以使用%% a。它應該仍然存在於內循環中......

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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/04/21/132566247e7541596d13144e479c7723.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com