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 need to create a folder (called "visitor") in every folder of one main folder. For example, my structure is this:


I need this:


Of course, there are some issues:

  1. I don't know the total numbers of folders in the root folder
  2. I don't know the real name of every folder
  3. I can't use any software or install anything more that comes with Windows XP (it's for a web server on staging and production)

I was thinking of doing this with a batch file (using for), but I can't work out how to get the names of the folders without parsing a file. Any ideas?

share|improve this question
up vote 1 down vote accepted

List all folders into a file:

dir /ad /b /s > dirlist.txt

For every directory, run mkdir:

for /f "tokens=*" %%a in (dirlist.txt) do mkdir "%%~a\visitor"

Delete temporary file:

del dirlist.txt

(It's possible to use dir... directly inside the for loop, but there is a risk of endless recursion.)

share|improve this answer
its works! thanks! But the way, it creates a visitor folder on root folder because ./ but is great. Thanks a lot, you solve me 3 days of typing (no joke) – Leandro Tupone Dec 5 '11 at 23:20

This seems to work with folder names that have spaces.

@echo off

set root_folder=%USERPROFILE%\Desktop\test

for /f "tokens=*" %%a in ('dir "%root_folder%" /ad /b') do @if not exist "%%~fa\visitor" md "%%~fa\visitor"

set root_folder=

You can make visitor folders in subfolders as well by adding /s to the DIR command, that is dir "%root_folder%" /ad /b /s. This does not seem to suffer any issues with recursion.

share|improve this answer
hi! thanks, how can you do it with folders with blank spaces? – Leandro Tupone Dec 5 '11 at 23:18
I updated it to include the tokens=* part and some quotation marks. – Patrick S. Dec 5 '11 at 23:33

for has a /d parameter that will list the directories instead of the files.

for /d %%i in (C:\Path\To\Root\*) do @md "%%i\visitor" should do the trick

share|improve this answer

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.