1

I have a list of 4000 .tif images that I need copied from a folder containing 20,000+ images.

I am trying to use command prompt to do so by using code found from googling my problem.

the code is as follows:

for /f %a in H:\list.txt do copy %a H:\new

"H:\list.txt" is my list file
"H:\new" is where i want my files to be copied to

I am running this command in the file folder that contains the .tif files H:\Doc2 and I keep getting:

H:\list.txt was unexpected at this time.

What is causing the issue? Is my list not correctly set up?

It looks like this:

ABBA.TIF
ABBD.TIF
ABBQ.TIF

Do i need commas or colons after the file names?

Lando
  • 715
  • 6
  • 29

2 Answers2

2

H:\list.txt is a literal, you want to loop over each of the lines of the file. Check this out:

How do you loop through each line in a text file using a windows batch file?

for /F "tokens=*" %%A in (myfile.txt) do [process] %%A

Suggestion: tag this with "windows" as well.

Community
  • 1
  • 1
Amir T
  • 2,708
  • 18
  • 21
2

Amir diagnosed your immediate problem - your code is missing the parentheses around the IN clause.

But you have another potential problem. Your list may include file names and or paths that contain spaces or other special characters. If so, then the name must be quoted.

The values in the list may already by quoted, or they may not. You can use the ~ modifier to strip any existing enclosing quotes that may or may not be there, and then explicitly add your own.

for /f %a in (H:\list.txt) do copy "%~a" H:\new

If you want to include the line in a batch file, then each % must be doubled as %%.

dbenham
  • 127,446
  • 28
  • 251
  • 390
  • `C:\Data\DM3 Marketing\Image Library>for /f %a in (C:\Data\list.txt) do copy "%~a" C:\Data\temp C:\Data\DM3 Marketing\Image Library>copy "for" C:\Data\temp The system cannot find the file specified.` is all I get – Bevan Dec 10 '15 at 21:51