什么相当于 Windows 中的 Linux mkdir -p?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/905226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is equivalent to Linux mkdir -p in Windows?
提问by Renjith G
In Linux, mkdir -p
creates a folder tree.
在 Linux 中,mkdir -p
创建文件夹树。
What is the equivalent option in Windows to create a folder tree? Is there any?
Windows 中创建文件夹树的等效选项是什么?有没有?
回答by paxdiablo
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:
如果启用了命令扩展,Windows mkdir 会自动执行此操作。它们几乎在我用过的每个盒子上,但如果没有,您可以创建自己的脚本来执行此操作:
@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).
命令扩展是 cmd.exe 的一个附加功能,它允许你做更多的事情(代价是与批处理语言的早期版本有一点兼容性)。
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.
cmd.exe
默认情况下,Windows XP应该启用这些扩展,但您可以配置您的机器,以便在默认情况下禁用它们("cmd /e:off"
用作默认处理器)。如果您这样做并想要使用扩展名,您的cmd
文件必须有一个 setlocal 来重新打开它们。
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.
上面的脚本可以称为 md2.cmd,然后您将保证能够创建多个目录级别,"md2 a\b\c"
而不必担心是否启用了扩展。
Almost every one of the cmd
scripts I write begins with:
cmd
我写的几乎每一个脚本都是从以下开始的:
setlocal enableextensions enabledelayedexpansion
to ensure I get as close as possible to the behavior of my beloved bash
:-)
以确保我尽可能接近我心爱的人的行为bash
:-)
回答by Alan Haggai Alavi
In Windows, mkdir
creates directory trees by default.
在 Windows 中,mkdir
默认情况下创建目录树。
mkdir a\b\c
mkdir a\b\c
回答by Nick Ko
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;
此外,unix 允许这样做;
mkdir -p src/main/java src/main/resources
where two branches will be created as shown below, the equivalent to that on windows is;
其中将创建两个分支,如下所示,相当于 windows 上的;
mkdir "src/java/resources" "src/main/resources"
mkdir "src/java/resources" "src/main/resources"
src
-----java
-------resources
-----main
-------resources
I hope this helps! xox
我希望这有帮助!xox
回答by Anup Thakare
If you want to use forward slashes, just give the directory structure you want within double quotes. mkdir "org/frame/bu/fed/config"
如果你想使用正斜杠,只需在双引号内给出你想要的目录结构。mkdir "org/frame/bu/fed/config"
回答by basit
mkdir by default makes all intermediate directories. Just ensure that you use '\' as the separator.
mkdir 默认创建所有中间目录。只需确保使用 '\' 作为分隔符。
回答by Intouchsiri Suksawasdipat
I just try to create multiple folders on today and it is working!
我今天只是尝试创建多个文件夹,它正在工作!
mkdir "templates" "static/css" "static/js"