34

I'm trying to create a folder named Design in the build output folder using th following commandline in the PostBuildEvent in visual studio

mkdir $(TargetDir)Design  ....Runs Successfully but folder is not created
mkdir "$(TargetDir)Design" ....Runs Successfully but folder is not created
MD $(TargetDir)Design  ....Runs Successfully but folder is not created
MD "$(TargetDir)Design"  ....Runs Successfully but folder is not created

Can anyone tell me what I'm doing wrong

Deepak
  • 731
  • 4
  • 11
  • 21
  • What's the value of your `TargetDir` ? – Tung May 09 '12 at 01:43
  • Its the relative path of the output saved in the buildserver for example \\build\Sol Build\Build_1120943.7 – Deepak May 09 '12 at 01:54
  • Your syntax looks good. Can you try adding an `echo` statement after your `mkdir` command as a sanity check to be sure that the computed path is where you think it is? – Tung May 09 '12 at 02:28
  • When you say "Run successfully" what do you mean? I explain, you see the compiler runs and that it compiles right, but how you can prove that the postbuild event is run? Do you set "Run Allways" on the "Run Post-Build event" combo? – Steve May 09 '12 at 12:18
  • I made it to run on successful build. The postbuildevent is running because there are other commandlines that deletes some files and rename some folders. But the problem is creating a new folder. – Deepak May 09 '12 at 16:14

3 Answers3

52

You need to do something like:

if not exist DirToCreate mkdir DirToCreate
Eric
  • 6,364
  • 1
  • 32
  • 49
25

This worked for me (where Design is the folder you want to create):

mkdir $(TargetDir)\Design

If you want to check for existence first:

if not exist $(TargetDir)\Design mkdir $(TargetDir)\Design
user2444499
  • 757
  • 8
  • 14
  • 9
    The Directory Path should be enclosed in Double Quotes as below: if not exist "$(TargetDir)\Design" mkdir "$(TargetDir)\Design" – Bala Sakthis Jul 10 '17 at 16:30
5

In addition to the two previous answers, you could use a variable like this :

SET path=$(TargetDir)\Design
if not exist "%path%" mkdir "%path%"

That way, you'll avoid any duplication. (Tested with VS2019)

Invvard
  • 1,497
  • 2
  • 15
  • 20