Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
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.

share|improve this answer
yip that was the problem cheers for that – Tim Feb 22 '10 at 21:51
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. ...

share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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