Not satisfied by the Answer? Still have doubts?
Ask Question

Create folder with batch but only if it doesn't already exist

Can anybody tell me how to do the following in in a Windows batch script? (*.bat):

Build a folder only if it doesn't already exist
In more detail, I want to create a folder named VTS on the C: drive, but only if that folder doesn't already exist. I don't want to overwrite the contents of the folder if it already exists and the batch is executed.
cmd batch-file windows

2 Answers

You just use this: if not exist "C:VTS" mkdir C:VTS it wll create a directory only if the folder does not exist.

Note that this existence test will return true only if VTS exists and is a directory. If it is not there, or is there as a file, the mkdir command will run, and should cause an error. You might want to check for whether VTS exists as a file as well.
mkdir C:VTS 2> NUL
create a folder called VTS and output A subdirectory or file TEST already exists to NUL.


(C:&(mkdir "C:VTS" 2> NUL))&
change the drive letter to C:, mkdir, output error to NUL and run the next command.

Login / Signup to Answer the Question.

  • Be descriptive with your answer, and try to avoid copy-pasting external links, instead guide the user who has asked the question, where can they find the detailed answer.
  • You cannot share any URL in answer.
  • To make a text bold, surround the text with single asterisk, for example *bold text*
  • To format a text like code, surround the text within double asterisk, for example **code**
  • To add a multiline piece of code, surround the whole code within triple asterisk, for example *** multiline code ***
  • Please verify before submitting the answer.