Search CFJ

July 30, 2008

Did you know? You can create multiple folders with one command in XP and Vista

Special thanks to Lee Mathews in the comments - he verified that this also works in XP!

Just the other day, I had to hop into the command window for Vista to do some folder creation and other tasks. Since I'm based in the days of DOS, I have a penchant for heading to the command window before "going GUI". Ok, so I'm a typing geek...anyhoo...

The cool thing about Vista's 'MD' (make directory) command is that it can create a tree of directories with a single command. But, I didn't know that you could create multiple directories at the same level with a single command.

If you need to create multiple folders with unique names, you can simply do it by using the 'MD' command in Vista's command shell, then use spaces between each folder name.

So, if you type:

md this is a test folder

You will get 5 separate folders, named the same as your parameters, respectively. So, when you perform a 'dir', you will get something like this:


If you want a folder called "This is a test folder", then you should enter the MD command like this:

md "this is a test folder"

Need to make multiple long folder names with spaces in them? Just enclose each name in quotes as separate command line parameters.

md "test a" "test b" "test c"



Sidebar:

I find that there are some strange idiosyncrasies between the various Windows flavors and how it handles file/folder operations. Case in point; Got a Windows 95 box around? Typing 'dir.exe' would produce the same results as 'dir *.exe', but it didn't in ME (did I just MEntion that spectacular failure of an operating system?), Windows 2000 or XP.

Pretty nifty!

6 comments:

Lee Mathews said...

pro tip: this works in XP, too...I never tried until I read your post, so thanks!

Anonymous said...

You can create a full tree if you want in one command.

For example:

md This\Is\A\Folder

will create

This
and
This\Is
and
This\Is\A
and
This\Is\A\Folder

all in one command.

Anonymous said...

Every "typing geek" knows this tip.

Anonymous said...

i have used this to create some folders... i need to create 5000+ folders, each numbered 10001 10002 10003 etc etc etc... this method is a lot quicker that creating individual folders out of the command prompt, but is there a way i can make one batch quickly, as it will still take ages to type in all the numbers?

thanks :-)

Jim's Spam dump said...

To create a large number of numbered folders quickly, you just need to know the minimum number, the maximum number, and the increment and use a FOR command.

As an example:

You want to start with a folder named 100001

and create sequentially numbered folders to 100020

Here is the FOR command you would use:

-----------
for /L %f in (100001, 1, 100020) do md %f
-----------

the /L says we're using a loop type of command, the parameters for the loop are: starting number, increment, ending number

I live and die by the FOR command, one of the most powerful but under rated things MS ever introduced in the command processor.

ben said...

Jim: FOR is awesome. thanks for the tip