Creating multiple sub-folders using MKDIR from a command prompt

Here is the situation. You need to create several subfolders inside a folder and name them appropriately.cprompt

One way is to create each folder one by one and then rename them again one at a time. This method would be fine if you had to create only a few folders. But what if you need to create several such folders. Doing it using the above method would be quite tedious and time consuming.

Here’s a little command prompt trick that can help you immensely.

  1. Open Notepad and type in a list of the names of the folders you need to create, with each name in a separate line.
  2. Save this file in the folder in which you want to create the sub-folders. This will save you the trouble of having to type out the entire path. Let’s call this file folders.txt.
  3. Open a command prompt in that folder and type:

FOR /F %n IN (folders.txt) DO MKDIR %n

and hit Enter. Within seconds the folder would all be created.

You can use any single letter instead of n, and the command will take each line of the file and DO a MKDIR with the name it finds.

A variant is to use:

FOR /F “tokens=*” %n IN (folders.txt) DO MKDIR %n

This version will process items on the same line, separated by spaces. To create folders with a space in the name, use the second method and enclose the name in double quotes. So, for example, a text file containing the line

“January February” March April May

will produce four folders when fed to the FOR command, the first being named “January February” and the others named March, April and May.

Comments

  1. awesome says

    Can you please continue – many helps thaks -

    can you see if you can handle this simple task for me?

    I have many folders with many required files with same extension in them.

    Like so
    C:\
    C:Photoshop\
    C:\Photoshop\templates
    C:\Photoshop\templates\template1\file.*
    C:\Photoshop\templates\template2\file.*
    C:\Photoshop\templates\template2\file.*

    Question how to execute all files from CMD window.
    Thanks !

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>