I was planning on using a command like this

FOR /R %f in (".") DO xcopt test.txt %f

to copy a file into all subdirectories of a folder.

This works fine when I write the file into the command prompt but it doesn't work when I put it into a batch file and run the batch file.

Any ideas as to why this wouldn't run from a batch file?

Thanks

link|improve this question

feedback

2 Answers

up vote 4 down vote accepted

It is probably to do with your %f in a batch file these should be %%f. This is to do with the way variable expansion is performed in batch files.

link|improve this answer
yip that was the problem cheers for that – Tim Feb 22 '10 at 21:51
feedback
for /?

brings up the help. The first paragraph of text mentions:

To use the FOR command in a batch program, specify %%variable instead of %variable. ...

link|improve this answer
good tip, but this would be better left as a comment on the accepted answer. – quack quixote Feb 23 '10 at 1:55
Maybe. I think it is useful information in its own right that could be missed if it were provided in a comment. I'll delete the reference to Martin's answer to remove the discussion feel of my answer. – Anthony Cramp Feb 24 '10 at 2:39
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.