Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

mkdir that overwrites any existing directory

Writer Matthew Barrera

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?

5 Answers

You can delete the build directory with

rd /s /q build

or

if exist build rd /s /q build
1

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 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:\users\name\build

For more on New-Item see:

1

You can try the rd command to remove the directory. You have to ensure the directory is empty first though.

1

This command can help:

mkdir -p a & rm -r a & mkdir a

This my answer in stackoverflow

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy