我想复制一组子文件夹,其中name contains
项目在列表中。该列表有一组代码(例如ABC1
,ABC2
),但文件夹名为ABC1_revised_2018
等。我放在一起的批处理文件如下。我得到的'"Usebackq tokens=^" was unexpected'
错误。
@ECHO ON
SET FileList=C:\filelist.txt
SET Source=C:\Files
SET Destination=C:\Files-Parsed
FOR /D "USEBACKQ TOKENS=^" %%D IN ("%FileList%") DO XCOPY /E /F /D "%Source%\%%~D" "%Destination%\"
GOTO :EOF
我试图使用^
来表示match beginning of string
,但显然不起作用。有任何想法吗?我已尝试使用批处理文件,并在cmd中逐行。
附加
Folder
-ABC1-text-date (this is a subfolder)
-ABC2-text-date
filelist.txt only has values like ABC1, ABC2, etc. not exact matches does this help?
好吧,如果你想通过目录递归并根据文件中的部分匹配复制子目录:
@echo off
set "FileList=C:\filelist.txt"
set "Source=C:\Files"
set "Destination=C:\Files-Parsed"
for /f "delims=" %%a in (%filelist%) do (
pushd %source%
for /f "delims=" %%i in ('dir /s /b /ad "%%a*"') do xcopy /E /F /D "%%~fi" "%Destination%"
popd
)
获取文件中的条目后,for /d
将在源目录中执行目录*的目录列表,并将dir物理复制为C:\source\*\ABC2018
等。