Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .