以下应该在批处理文件中工作:
FOR /F %%F IN (Textfile.txt) DO xcopy /I /E "C:\Source\%%F" "D:\Dest\%%F"
您还可以应用更多开关:
/C Continues copying even if errors occur.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
更新
在您的特定情况下,当您拥有分散在子文件夹中的文件夹列表时,此脚本应该可以工作:
@echo off
set SRC_FOLDER="C:\Source"
set DST_FOLDER="C:\Destination"
REM this makes sure that if the first folder in list is empty - it is copied
IF NOT EXIST %DST_FOLDER% MKDIR %DST_FOLDER%
REM loop through the items in list; use one per line
REM for group match use <NAME>*
FOR /f %%F IN (%~dp0\Textfile.txt) DO (
REM loop through all folders
FOR /f "delims=" %%D IN ('DIR %SRC_FOLDER% /A:D /B') DO (
REM loop through FOLDER/NAME* sub-folders
FOR /f "delims=" %%G IN ('DIR %SRC_FOLDER%\"%%D\%%F" /A:D /B') DO (
IF EXIST %SRC_FOLDER%\"%%D\%%G" XCOPY /I /E %SRC_FOLDER%\"%%D\%%G" %DST_FOLDER%\"%%~nG"
)
REM loop through all FOLDER subfolders to catch NAME subfolders
FOR /f "delims=" %%G IN ('DIR %SRC_FOLDER%\"%%D" /A:D /B') DO (
IF "%%G" == "%%F" XCOPY /I /E %SRC_FOLDER%\"%%D\%%G" %DST_FOLDER%\"%%~nG"
)
)
)
- 请注意,需要“delims=”参数来正确处理带有空格的路径。
enter code here