2

Can someone please tell me hwo can I delete both Debug and Release folder of every project in my solution?

I found this code in this post but I have no idea where should I put this!

FOR /F "tokens=*" %%G IN ('DIR /B /AD /S bin') DO RMDIR /S /Q "%%G"
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S obj') DO RMDIR /S /Q "%%G"

The reason is, I have to manually close Visual Studio, remove all the debug and release folders, re open the soloution and rebuild....only then my appllication compiles and works correctly!

Community
  • 1
  • 1
Saeid Yazdani
  • 12,365
  • 48
  • 158
  • 270

3 Answers3

4

There are a number of good alternate solutions in the "I want to delete all bin and obj folders to force all projects to rebuild everything" thread you referred to, but if you want to use this command line it needs tweaking for Release and Debug:

DIR /B /AD /S bin

This says to output all directories (/AD) in and under the current directory (/S) named bin (or obj in the second invocation). You would want to do this for Debug and Release instead of bin and obj.

FOR /F "tokens=*" %%G IN ('DIR /B /AD /S Release') DO RMDIR /S /Q "%%G"
FOR /F "tokens=*" %%G IN ('DIR /B /AD /S Debug') DO RMDIR /S /Q "%%G"

As Stuart says, a batch file (or command line invocation) with those two commands and run from the project root will remove all directories named Release or Debug and their contents. It won't be smart and know that these are the configured release and debug directories for the project.

Using a tool that knows about the project configuration files and acting based on them would be safer. Again there are some ideas on those in the other thread you linked.

Community
  • 1
  • 1
jla
  • 5,554
  • 2
  • 30
  • 34
2

Just want to add to jla's answer (because I don't know how to comment, or I cannot comment yet):

You can even put debug and release into one command (and even .svn folders). For example:

FOR /F "tokens=*" %G IN ('DIR /B /AD /S Release Debug .svn') DO RMDIR /S /Q "%G"

Here I replaced the double %% into single % because it's now a single command and you can just run it from command line.

Hope this helps.

Roy
  • 790
  • 1
  • 7
  • 25
0

The batch file I use for this also cleans up the packages and all non essential clutter in order to properly backup the folder. I use this code inside the batch file and run the batch file from the root directory of the solution (in my case the root directory where all the solution lives)

for /d /r . %%d in (bin,obj,csx,rcf,_ReSharper.*) do @if exist "%%d" rd /s/q "%%d"
for /d /r . %%d in (packages) do @if exist "%%d" (
    cd %%d
    for /d /r . %%e in (*) do @if exist "%%e" rd /s/q "%%e"
)
Low Flying Pelican
  • 5,792
  • 1
  • 26
  • 41