-1

I want to copy a set of subfolders where name contains items on a list. The list has a set of codes (e.g. ABC1, ABC2) but the folders are named ABC1_revised_2018, etc. My batch file I put together is below. What I am getting a '"Usebackq tokens=^" was unexpected' error.

@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

I am attempting to use ^ to denote match beginning of string but that clearly isn't working. Any ideas? I have tried with a batch file and also line by line in cmd.

append

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?
sibelius3
  • 1
  • 1

1 Answers1

1

Well, if you want to recurse through directories and copy sub directories as per partial matches inside the file:

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

after getting the entry in the file, for /d will do a directory listing of the directory* in the source directory and physically copy the dir as C:\source\*\ABC2018 etc.

Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • thank you, this runs without errors, but doesn't seem to search subfolders. The subfolders I'm looking to copy would be found at c:\files\folder\abc1, etc. Would I need to adjust how I reference the source? – sibelius3 Feb 21 '19 at 21:00
  • @sibelius ok did not know that. Will update answer now. – Gerhard Feb 22 '19 at 06:09