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 am a two day noobie & need some help. I want to create a folder on the Desktop called 2013 Dec. Vacation & have sequentially dated folders 2013-12-01 to 2013-12-31 nested inside the main folder. The following command works but it give an error message on days 10 to 31(A Subdirectory or File Already Exists.) Can someone refine this command.

Thanks

 for /l %a in (1,1,9) do md "C:\Users\b\Desktop\2013 Dec. Vacation\2013-12-0%a" & for /l %a in (10,1,31) do md "C:\Users\b\Desktop\2013 Dec. Vacation\2013-12-%a"
share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

It’s treating your command as if it were

for /l %a in (1,1,9) do (
    md "C:\Users\b\Desktop\2013 Dec. Vacation\2013-12-0%a"
    for /l %a in (10,1,31) do md "C:\Users\b\Desktop\2013 Dec. Vacation\2013-12-%a"
)

so the second FOR loop is executed nine times.

Why not just do it as two lines?:

for /l %a in (1,1,9)  do md "C:\Users\b\Desktop\2013 Dec. Vacation\2013-12-0%a"
for /l %a in (10,1,31) do md "C:\Users\b\Desktop\2013 Dec. Vacation\2013-12-%a"

Or, if you really want to do it all on one line, add parentheses as shown below:

( for /l %a in (1,1,9) do md "C:\Users\b\Desktop\2013 Dec. Vacation\2013-12-0%a" )  &  for /l %a in (10,1,31) do md "C:\Users\b\Desktop\2013 Dec. Vacation\2013-12-%a"
share|improve this answer
    
Thanks for the lesson Scott. Adding the Parentheses suggestion was exactly what I wanted. Works great. –  user202151 Feb 28 '13 at 14:52
    
@user202151: Glad to help (and welcome to Super User). –  Scott Feb 28 '13 at 16:40
    
@user202151: May I draw your attention to the How do I ask questions? section of the Super User FAQ (Frequently Asked Questions) –– “When you have decided which answer is the most helpful to you, mark it as the accepted answer by clicking on the check box outline to the left of the answer.” If you do that, we both benefit. After you have earned some more reputation, you can also vote up helpful answers by clicking the upward pointing arrow to the left of the answer. –  Scott Feb 28 '13 at 16:40
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.