14

I'm trying to delete a folder in my output directory using the following command line:

del /F "$(TargetDir)Content\"

Tho I always end up exiting with error code 1. I've tried several different ways, without /F, with/without slash both before and after, etc.

Error   1   The command "del /F "E:\proj\bin\Windows\Debug\Content\"" exited with code 1.

There are a lot of questions regarding deleting files in post-build event command lines in visual studio, which works fine, but I can't seem to delete a folder without getting code 1.

Any help is appreciated!

jsmars
  • 1,640
  • 5
  • 21
  • 33
  • Have you set `Tools.Options.Projects and Solutions.Build and Run.Log verbosity = Diagnostic` and had a look in the log file? – PJTraill May 28 '15 at 23:10
  • 4
    You probably need to add /Q to turn off the "are you sure" prompt. If you want to delete the folder itself as well as the contents of the folder you should use RD not DEL. – Frank Boyne May 28 '15 at 23:54
  • Thanks, RD /S /Q worked, should have written it as answer! Tried diagnostic and it did show the Y/N dialog, adding /Q removed the error but the folder still wasn't being deleted, seems I was using the wrong command for folders.. Tried deltree but it seems that command doesn't exist anymore so I thought del was the correct command. – jsmars May 29 '15 at 06:22

2 Answers2

22
RD /S /Q "Full Path of Folder"

In your case:

RD /S /Q "$(TargetDir)Content\"
Sergey Kulgan
  • 1,215
  • 1
  • 12
  • 12
2

Browse to the same folder using Command Prompt, and then run that command and see what the actual error is. Might be permissions or something is in use.

Michal Ciechan
  • 13,492
  • 11
  • 76
  • 118
  • 2
    It did help me find that I needed a /Q command, which removed the error, but the folder still wasn't being deleted. RD /S /Q was the correct command to use for folders it seems. – jsmars May 29 '15 at 06:26