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

\idontknowthename1\
\idontknowthename2\
\idontknowthename3\
\idontknowthename4\
\idontknowthename5\

I need this:

\idontknowthename1\visitor
\idontknowthename2\visitor
\idontknowthename3\visitor
\idontknowthename4\visitor
\idontknowthename5\visitor

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

3 Answers

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 Dec 5 '11 at 23:20
add comment

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

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