xcopy批处理问题

问题描述 投票:-1回答:1

我想复制一组子文件夹,其中name contains项目在列表中。该列表有一组代码(例如ABC1ABC2),但文件夹名为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?
batch-file xcopy
1个回答
1
投票

好吧,如果你想通过目录递归并根据文件中的部分匹配复制子目录:

@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等。

© www.soinside.com 2019 - 2024. All rights reserved.