0

I have a batch file that is supposed to help me go find and copy a list of files to another folder. The list of files is in a .csv file separated with commas, for example xyz123,abc456. But the script only finds and copies the first file then stops. Can anyone help me understand why it doesn't continue? Here's the code:

@ECHO OFF
set FIILELIST=C:\job\crcfilelist.txt
set FILESPATH=C:\filesource
set DESTPATH=C:\job\

for /f "delims=," %%x in (%FIILELIST%) do (forfiles /p %FILESPATH% /s /m %%x.* /c "cmd /c copy /y @path %DESTPATH%\@file" 2>>failed_temp.txt)

PAUSE

Note: I got this from another post on this forum but I can't remember where. Thanks to whoever wrote it.

OutThere
  • 467
  • 2
  • 8
  • 19

1 Answers1

0

FOR /F will read the file and assign the metavariable (in this case, %%x) with the first "token" in the line (tokens are separated by the delims character-set).

Then it goes on to the next line and repeats.

Try

for /f "delims=" %%q in (csvfilename) do for %%x in (%%q) do ...

which will assign the entirety of the line from the file to %%q and since this is a comma-separated list, %%x will see a comma-separated list and happily execute your command using each comma-separated token.

See for /? from the prompt for documentation - or thousands of examples on SO.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Magoo
  • 77,302
  • 8
  • 62
  • 84