How to delete files in Visual Studio Pre-build event command line

Visual StudioCommand LineBuild ProcessPre Build-Event

Visual Studio Problem Overview


I am trying to delete files in my $(TargetDir) within visual studio before building a project.

How do you have to format command line to get around this problem I am getting below? alt text

Visual Studio Solutions


Solution 1 - Visual Studio

Try

cd $(TargetDir)
del *.tif

As jvenema pointed out, your $(TargetDir) is expanding into a path containing spaces in the folder names which is breaking the delete command.

Solution 2 - Visual Studio

I ended up using rd /s /q "$(TargetDir)" to clean out the directory. As far as I know it is working.

Solution 3 - Visual Studio

Try adding quotes around the directory.

Solution 4 - Visual Studio

You have to write del "$(TargetDir)*.tif" because of spaces in directory path.

Solution 5 - Visual Studio

Old question but a couple of things:

del "$(TargetDir)*.tif" /q
  1. /q is for quiet. Otherwise, del cmd prompts "... Are you sure (Y/N)?" which the build does not like.

  2. As many have pointed out, "" around the targetDir for possible space in the target directory.

Solution 6 - Visual Studio

wmic process where name='chromedriver.exe' delete

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiondance2dieView Question on Stackoverflow
Solution 1 - Visual StudioEoin CampbellView Answer on Stackoverflow
Solution 2 - Visual StudiotuckView Answer on Stackoverflow
Solution 3 - Visual StudioJerod VenemaView Answer on Stackoverflow
Solution 4 - Visual StudioVáclav DajbychView Answer on Stackoverflow
Solution 5 - Visual StudioSudip ShresthaView Answer on Stackoverflow
Solution 6 - Visual StudioMeg-90View Answer on Stackoverflow