'What is the equivalent of mkdir -p on Windows 10?

I've been unable to find help files on Windows for things like MD, mkdir or new-item. Doing update-help just throws errors.

How do I do mkdir -p on Windows 10 in Command Prompt?

I want to create a directory even if that directory already exists.



Solution 1:[1]

Use mkdir /? to get information on the command. -p is not a flag in Windows, parent/intermediate directories will be created if command extensions are turned on.

See this Microsoft documentation for more information.

Solution 2:[2]

Since mkdir in Windows 10 (even with command extensions enabled) does not the job, here is the content of my mkdir.bat that DOES it for a %path% at a %drive% :)

@ECHO OFF
SETLOCAL enableextensions
SETLOCAL enabledelayedexpansion

REM ## Create directory structure levelwise since there is nothing like "mkdir -p"

REM ## substitute "\" with ";"
SET "pathParts=%path:\=;%"

REM ## iterate over a list of the tokens between " ", ",", ";" or "=" 
SET pathToMake=%drive%

FOR %%d IN (%pathParts::= %) DO (
    SET pathToMake=!pathToMake!\%%d
    ECHO !pathToMake!
    IF NOT EXIST !pathToMake! MKDIR !pathToMake!
)

Just call it like that:

D:\>SET drive=D:

D:\>SET path=XYZ\123\ABC

D:\>mkdir.bat
D:\XYZ
D:\XYZ\123
D:\XYZ\123\ABC

And et voilà: D:\XYZ\123\ABC exists :)

Solution 3:[3]

mkdir of Windows 10 does not support -p or /p or an equivalent flag.

If you want realize the -p functionality according to Unix operating systems you can do that in one line as follows:

set MKDIR_DIR=D:\XYZ\123\ABC && if not exist %MKDIR_DIR% mkdir %MKDIR_DIR%

Replace D:\XYZ\123\ABC with the desired directory.

Solution 4:[4]

There is very easy solution in windows. -p is not required at all. If you want to create nested folders then write like below:

mkdir \Taxes\Property\Current

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/mkdir

Solution 5:[5]

On Windows 11 Pro using bash this command did the job for me:

mkdir.exe -p folder/subFolder

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/mkdir

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mech
Solution 2 Alexander Schäl
Solution 3 gotwo
Solution 4 Vedthedataguy
Solution 5