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 having difficulty getting the (simplified) batch-file below to work. It creates the a specific folder in all sub-directories of the specified directory.

@echo off
setlocal
set "location=c:\test"
for /d %%d in (%location%\*) do (
  md "%%d\COMMONFOLDER"
)
share|improve this question
1  
What isn't working? What is your question? –  dbenham Sep 4 '13 at 19:22
    
Does the containing folder (e.g., c:\test) exist? Does it contain any folders? Are you getting an error? –  Synetech Sep 4 '13 at 19:31

2 Answers 2

up vote 0 down vote accepted
setlocal
set location=c:\test
FOR /D %%C in ("%location%\*") DO md %%C\COMMONFOLDER

works fine for me, any direct subfolders get a COMMONFOLDER made inside them.

eg.

  • C:\test\SubLevel1\ gets a C:\test\SubLevel1\COMMONFOLDER
  • C:\test\SubLevel1-1\ gets a C:\test\SubLevel1-1\COMMONFOLDER
  • C:\test\SubLevel1\SubLev2 would not get a COMMONFOLDER

Not sure if this helps, but just add the @ECHO off and it works exactly as you said you wanted it to.

share|improve this answer
@echo off
setlocal
set "location=c:\test"
for /r "%location%" /d %%d in (*) do (
  md "%%d\COMMONFOLDER"
)
share|improve this answer

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.