mkdir that overwrites any existing directory

Multi tool use
If I try to run mkdir build
to create a build
directory, if the directory already exists, this error is thrown: A subdirectory or file build already exists.
. I need to delete and overwrite this directory. What is the command for that?
windows command-line mkdir
add a comment |
If I try to run mkdir build
to create a build
directory, if the directory already exists, this error is thrown: A subdirectory or file build already exists.
. I need to delete and overwrite this directory. What is the command for that?
windows command-line mkdir
add a comment |
If I try to run mkdir build
to create a build
directory, if the directory already exists, this error is thrown: A subdirectory or file build already exists.
. I need to delete and overwrite this directory. What is the command for that?
windows command-line mkdir
If I try to run mkdir build
to create a build
directory, if the directory already exists, this error is thrown: A subdirectory or file build already exists.
. I need to delete and overwrite this directory. What is the command for that?
windows command-line mkdir
windows command-line mkdir
edited Jan 1 at 18:12


valiano
229110
229110
asked Aug 19 '12 at 21:14
Shawn McleanShawn Mclean
2234616
2234616
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
You can delete the build directory with
rd /s /q build
or
if exist build rd /s /q build
add a comment |
I don't think it is possible to use the mkdir
command to do that natively (though if you were will to do a bit more scripting, it would be possible).
A simple alternative is the following command in powershell:
New-Item path -type directory -force
Where path
is something like C:usersnamebuild
For more on New-Item
see: http://technet.microsoft.com/en-us/library/ee176914.aspx
I can't execute powershell as I'm calling this from a rake script.
– Shawn Mclean
Aug 19 '12 at 21:29
add a comment |
I wanted to create directory only if it does not exist
If it exists, nothing to do
Below worked great in the bat file:
if not exist someDir1 mkdir someDir1
add a comment |
You can try the rd
command to remove the directory. You have to ensure the directory is empty first though.
This throws an error if there are elements in the directory.
– Shawn Mclean
Aug 19 '12 at 21:27
add a comment |
This command can help:
mkdir -p a & rm -r a & mkdir a
This my answer in stackoverflow
1
Please read the question again carefully. Your answer does not answer the original question. OP is using Windows not Unix.
– DavidPostill♦
Aug 27 '16 at 7:16
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f463690%2fmkdir-that-overwrites-any-existing-directory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can delete the build directory with
rd /s /q build
or
if exist build rd /s /q build
add a comment |
You can delete the build directory with
rd /s /q build
or
if exist build rd /s /q build
add a comment |
You can delete the build directory with
rd /s /q build
or
if exist build rd /s /q build
You can delete the build directory with
rd /s /q build
or
if exist build rd /s /q build
answered Aug 19 '12 at 21:55
Harry JohnstonHarry Johnston
4,41152349
4,41152349
add a comment |
add a comment |
I don't think it is possible to use the mkdir
command to do that natively (though if you were will to do a bit more scripting, it would be possible).
A simple alternative is the following command in powershell:
New-Item path -type directory -force
Where path
is something like C:usersnamebuild
For more on New-Item
see: http://technet.microsoft.com/en-us/library/ee176914.aspx
I can't execute powershell as I'm calling this from a rake script.
– Shawn Mclean
Aug 19 '12 at 21:29
add a comment |
I don't think it is possible to use the mkdir
command to do that natively (though if you were will to do a bit more scripting, it would be possible).
A simple alternative is the following command in powershell:
New-Item path -type directory -force
Where path
is something like C:usersnamebuild
For more on New-Item
see: http://technet.microsoft.com/en-us/library/ee176914.aspx
I can't execute powershell as I'm calling this from a rake script.
– Shawn Mclean
Aug 19 '12 at 21:29
add a comment |
I don't think it is possible to use the mkdir
command to do that natively (though if you were will to do a bit more scripting, it would be possible).
A simple alternative is the following command in powershell:
New-Item path -type directory -force
Where path
is something like C:usersnamebuild
For more on New-Item
see: http://technet.microsoft.com/en-us/library/ee176914.aspx
I don't think it is possible to use the mkdir
command to do that natively (though if you were will to do a bit more scripting, it would be possible).
A simple alternative is the following command in powershell:
New-Item path -type directory -force
Where path
is something like C:usersnamebuild
For more on New-Item
see: http://technet.microsoft.com/en-us/library/ee176914.aspx
answered Aug 19 '12 at 21:23
soandossoandos
20.2k2892130
20.2k2892130
I can't execute powershell as I'm calling this from a rake script.
– Shawn Mclean
Aug 19 '12 at 21:29
add a comment |
I can't execute powershell as I'm calling this from a rake script.
– Shawn Mclean
Aug 19 '12 at 21:29
I can't execute powershell as I'm calling this from a rake script.
– Shawn Mclean
Aug 19 '12 at 21:29
I can't execute powershell as I'm calling this from a rake script.
– Shawn Mclean
Aug 19 '12 at 21:29
add a comment |
I wanted to create directory only if it does not exist
If it exists, nothing to do
Below worked great in the bat file:
if not exist someDir1 mkdir someDir1
add a comment |
I wanted to create directory only if it does not exist
If it exists, nothing to do
Below worked great in the bat file:
if not exist someDir1 mkdir someDir1
add a comment |
I wanted to create directory only if it does not exist
If it exists, nothing to do
Below worked great in the bat file:
if not exist someDir1 mkdir someDir1
I wanted to create directory only if it does not exist
If it exists, nothing to do
Below worked great in the bat file:
if not exist someDir1 mkdir someDir1
answered Jun 15 '17 at 11:04


Manohar Reddy PoreddyManohar Reddy Poreddy
1515
1515
add a comment |
add a comment |
You can try the rd
command to remove the directory. You have to ensure the directory is empty first though.
This throws an error if there are elements in the directory.
– Shawn Mclean
Aug 19 '12 at 21:27
add a comment |
You can try the rd
command to remove the directory. You have to ensure the directory is empty first though.
This throws an error if there are elements in the directory.
– Shawn Mclean
Aug 19 '12 at 21:27
add a comment |
You can try the rd
command to remove the directory. You have to ensure the directory is empty first though.
You can try the rd
command to remove the directory. You have to ensure the directory is empty first though.
edited Sep 14 '12 at 13:16


Dave
23.3k74363
23.3k74363
answered Aug 19 '12 at 21:25
HenryHenry
1
1
This throws an error if there are elements in the directory.
– Shawn Mclean
Aug 19 '12 at 21:27
add a comment |
This throws an error if there are elements in the directory.
– Shawn Mclean
Aug 19 '12 at 21:27
This throws an error if there are elements in the directory.
– Shawn Mclean
Aug 19 '12 at 21:27
This throws an error if there are elements in the directory.
– Shawn Mclean
Aug 19 '12 at 21:27
add a comment |
This command can help:
mkdir -p a & rm -r a & mkdir a
This my answer in stackoverflow
1
Please read the question again carefully. Your answer does not answer the original question. OP is using Windows not Unix.
– DavidPostill♦
Aug 27 '16 at 7:16
add a comment |
This command can help:
mkdir -p a & rm -r a & mkdir a
This my answer in stackoverflow
1
Please read the question again carefully. Your answer does not answer the original question. OP is using Windows not Unix.
– DavidPostill♦
Aug 27 '16 at 7:16
add a comment |
This command can help:
mkdir -p a & rm -r a & mkdir a
This my answer in stackoverflow
This command can help:
mkdir -p a & rm -r a & mkdir a
This my answer in stackoverflow
edited May 23 '17 at 12:41
Community♦
1
1
answered Aug 26 '16 at 16:32
Daniel Antonio Nuñez CarhuayoDaniel Antonio Nuñez Carhuayo
952
952
1
Please read the question again carefully. Your answer does not answer the original question. OP is using Windows not Unix.
– DavidPostill♦
Aug 27 '16 at 7:16
add a comment |
1
Please read the question again carefully. Your answer does not answer the original question. OP is using Windows not Unix.
– DavidPostill♦
Aug 27 '16 at 7:16
1
1
Please read the question again carefully. Your answer does not answer the original question. OP is using Windows not Unix.
– DavidPostill♦
Aug 27 '16 at 7:16
Please read the question again carefully. Your answer does not answer the original question. OP is using Windows not Unix.
– DavidPostill♦
Aug 27 '16 at 7:16
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f463690%2fmkdir-that-overwrites-any-existing-directory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1qk0FHusG8yGZvwQaKDTHbkvYIfo V6vjEMP vp8Cm,96HqwujBZOP3iurOrwAFg2hi jvYo7xUA,zrs1eN,q36o,6Y