What is equivalent to Linux mkdir -p in Windows?

WindowsBatch FileCmdMkdir

Windows Problem Overview


In Linux, mkdir -p creates a folder tree.

What is the equivalent option in Windows to create a folder tree? Is there any?

Windows Solutions


Solution 1 - Windows

The Windows mkdir does it automatically if command extensions are enabled. They are on just about every box I've ever used but, if they're not, you can create your own script to do it:

@echo off
setlocal enableextensions
md %1
endlocal

Expanding:

Command extensions are an added feature of cmd.exe which allows you to do so much more (at the cost of a little compatibility with earlier incarnations of the batch language).

Windows XP cmd.exe should have these extensions enabled by default but you can configure your box so that they're disabled by default (using "cmd /e:off" as the default processor). If you do that and want to use the extensions, your cmd files must have a setlocal to turn them back on.

The script above could be called md2.cmd and then you would be guaranteed to be able to create multiple directory levels with "md2 a\b\c" without having to worry whether the extensions were enabled.

Almost every one of the cmd scripts I write begins with:

setlocal enableextensions enabledelayedexpansion

to ensure I get as close as possible to the behavior of my beloved bash :-)

Solution 2 - Windows

In Windows, mkdir creates directory trees by default.

mkdir a\b\c

Solution 3 - Windows

For a strange reason when I attempted to create a directory with the following method;

mkdir src/main/java/main/resources 

it didn't work, I had to surround the path in double quotes, as shown below;

mkdir "src/main/java/main/resources"

Additionally, unix allows for this;

mkdir -p src/main/java src/main/resources

where two branches will be created as shown below, the equivalent to that on windows is;

mkdir "src/java/resources" "src/main/resources"

src
-----java
-------resources
-----main
-------resources

I hope this helps! xox

Solution 4 - Windows

If you want to use forward slashes, just give the directory structure you want within double quotes. mkdir "org/frame/bu/fed/config"

Solution 5 - Windows

mkdir by default makes all intermediate directories. Just ensure that you use '' as the separator.

Solution 6 - Windows

I just try to create multiple folders on today and it is working!

mkdir "templates" "static/css" "static/js"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRenjith GView Question on Stackoverflow
Solution 1 - WindowspaxdiabloView Answer on Stackoverflow
Solution 2 - WindowsAlan Haggai AlaviView Answer on Stackoverflow
Solution 3 - WindowsNick KoView Answer on Stackoverflow
Solution 4 - WindowsAnup ThakareView Answer on Stackoverflow
Solution 5 - WindowsbasitView Answer on Stackoverflow
Solution 6 - WindowsIntouchsiri SuksawasdipatView Answer on Stackoverflow