Can anybody tell me how to do the following in in a Windows batch script? (*.bat
):
- Create 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.
Just call
mkdir C:\VTS
no matter what. It will simply report that the subdirectory already exists.Edit: As others have noted, this does set the %ERRORLEVEL% if the folder already exists. If your batch (or any processes calling it) doesn't care about the error level, this method works nicely. Since the question made no mention of avoiding the error level, this answer is perfectly valid. It fulfills the needs of creating the folder if it doesn't exist, and it doesn't overwrite the contents of an existing folder. Otherwise follow Martin Schapendonk's answer.
You can use:
You can also expand the code to replace any missing expected files.