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

前端 未结 9 1756
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-12 09:03

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
9条回答
  •  忘掉有多难
    2020-12-12 09:57

    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.

提交回复
热议问题