Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

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.

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

Your Answer

 
discard

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.