mkdir that overwrites any existing directory












13















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?










share|improve this question





























    13















    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?










    share|improve this question



























      13












      13








      13








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 18:12









      valiano

      229110




      229110










      asked Aug 19 '12 at 21:14









      Shawn McleanShawn Mclean

      2234616




      2234616






















          5 Answers
          5






          active

          oldest

          votes


















          11














          You can delete the build directory with



          rd /s /q build


          or



          if exist build rd /s /q build





          share|improve this answer































            2














            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






            share|improve this answer
























            • I can't execute powershell as I'm calling this from a rake script.

              – Shawn Mclean
              Aug 19 '12 at 21:29



















            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





            share|improve this answer































              0














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






              share|improve this answer


























              • This throws an error if there are elements in the directory.

                – Shawn Mclean
                Aug 19 '12 at 21:27



















              -3














              This command can help:



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


              This my answer in stackoverflow






              share|improve this answer





















              • 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













              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
              });


              }
              });














              draft saved

              draft discarded


















              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









              11














              You can delete the build directory with



              rd /s /q build


              or



              if exist build rd /s /q build





              share|improve this answer




























                11














                You can delete the build directory with



                rd /s /q build


                or



                if exist build rd /s /q build





                share|improve this answer


























                  11












                  11








                  11







                  You can delete the build directory with



                  rd /s /q build


                  or



                  if exist build rd /s /q build





                  share|improve this answer













                  You can delete the build directory with



                  rd /s /q build


                  or



                  if exist build rd /s /q build






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Aug 19 '12 at 21:55









                  Harry JohnstonHarry Johnston

                  4,41152349




                  4,41152349

























                      2














                      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






                      share|improve this answer
























                      • I can't execute powershell as I'm calling this from a rake script.

                        – Shawn Mclean
                        Aug 19 '12 at 21:29
















                      2














                      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






                      share|improve this answer
























                      • I can't execute powershell as I'm calling this from a rake script.

                        – Shawn Mclean
                        Aug 19 '12 at 21:29














                      2












                      2








                      2







                      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






                      share|improve this answer













                      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







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      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



















                      • 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











                      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





                      share|improve this answer




























                        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





                        share|improve this answer


























                          1












                          1








                          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





                          share|improve this answer













                          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






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 15 '17 at 11:04









                          Manohar Reddy PoreddyManohar Reddy Poreddy

                          1515




                          1515























                              0














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






                              share|improve this answer


























                              • This throws an error if there are elements in the directory.

                                – Shawn Mclean
                                Aug 19 '12 at 21:27
















                              0














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






                              share|improve this answer


























                              • This throws an error if there are elements in the directory.

                                – Shawn Mclean
                                Aug 19 '12 at 21:27














                              0












                              0








                              0







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






                              share|improve this answer















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







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              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



















                              • 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











                              -3














                              This command can help:



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


                              This my answer in stackoverflow






                              share|improve this answer





















                              • 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


















                              -3














                              This command can help:



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


                              This my answer in stackoverflow






                              share|improve this answer





















                              • 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
















                              -3












                              -3








                              -3







                              This command can help:



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


                              This my answer in stackoverflow






                              share|improve this answer















                              This command can help:



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


                              This my answer in stackoverflow







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              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
















                              • 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




















                              draft saved

                              draft discarded




















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Список кардиналов, возведённых папой римским Каликстом III

                              Deduzione

                              Mysql.sock missing - “Can't connect to local MySQL server through socket”