Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is equivalent to Linux mkdir -p in Windows?

In Linux, mkdir -p creates a folder tree.

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

like image 387
Renjith G Avatar asked May 25 '09 03:05

Renjith G


People also ask

What is mkdir P in Windows?

Creates a directory or subdirectory. Command extensions, which are enabled by default, allow you to use a single mkdir command to create intermediate directories in a specified path. This command is the same as the md command.

Is mkdir same as md?

The md and mkdir commands are functionally identical. You can also create new folders in Windows Explorer by going to File → New → Folder. You may indicate an absolute or relative path for the path parameter. When absolute, the new directory is created as specified from the root directory.

What is mkdir P Linux?

Linux Directories mkdir -pIt will create parent directory first, if it doesn't exist. But if it already exists, then it will not print an error message and will move further to create sub-directories. This command is most helpful in the case when you don't know whether a directory alredy exists or not.

What does P mean in Linux?

This answer is not useful. Show activity on this post. -p is short for --parents - it creates the entire directory tree up to the given directory. E.g., suppose there are no directories in your current directory. If you execute: mkdir a/b/c.


1 Answers

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 :-)

like image 85
paxdiablo Avatar answered Sep 22 '22 13:09

paxdiablo