76
votes

I have a directory with many sub-directories. In each folder there is a subversion folder (.svn).

Is there a command in windows that will go through each folder and sub-directory and delete the .svn folder?

Or will I have to create a script or do it manually?

8
If it must not be scripted, I would just search for ".svn" in the root folder, then select all the results, and delete.JB Nizet
You might also be interested in the svn export command (svnbook.red-bean.com/en/1.0/re10.html), which copies a directory to another location, but without all the .svn directories.JB Nizet
@JB Nizet: You should create an answer so people can vote, instead of adding comments. Comments are for commenting on the question, eg when something's unclearSander Rijken
possible duplicate of [Removing .svn files from all directories ](stackoverflow.com/questions/1301203/…)Sander Rijken
@user538442 Please consider changing your accepted answerBrian Webster

8 Answers

176
votes

Make a litte batch file with the following line and execute it from the parent folder under which there are .svn directories.

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

You can also issue the line below straight from the Command Prompt:

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

Do this in PowerShell.

NOTE: This is recursive so be sure you are in the right directory!

gci -fil '.svn' -r -force | ri -r -force

Here is the rest of my source tree cleanup script.

gci -fil 'bin' -r -force | ri -r -force
gci -fil 'obj' -r -force | ri -r -force
gci -fil '_ReSharper*' -r -force | ri -r -force
gci -fil '*.suo' -r -force | ri -r -force
gci -fil '*.user' -r -force | ri -r -force
31
votes

Use the svn export command to export a Subversion working copy into a new "clean" directory structure that doesn't have the .svn directories.

10
votes

If you want to delete all sub folders named .svn in windows then create batch file with this content:

for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *.svn') do (
rd /s /q "%%i"
)

save it in a file del_All_Dot_SVN_Folders.cmd . Run it. You're done.

Thanks to http://www.axelscript.com/2008/03/11/delete-all-svn-files-in-windows/

Remember the above code has .svn whereas the code in the link has only *svn so its better to have the .svn to not accidentally have undesired effect.

10
votes

Just type .svn in the search box of the File Explorer, then select and delete all search results (see JB Nizet's comment). This method can of course also be used to quickly delete the obj and bin directories, e.g. when organizing svn archives.

Although OP asked for a commandline solution, he also indicated using Windows, and considered a manual deletion, so the File Explorer method could still be considered, especially because it is the fastest method and does not rely on 'tools' like svn export.

Although OP already selected an accepted answer, this answer might still be useful for others. At least it was useful for me, a long time linux / windows user who prefers command lines and first learned about the search box by this post :-)

explorer screenshot with searchbox

1
votes

Sorry for being late to the party but here's another one in a single line:

for /r %i in (.svn) do rmdir /s /q "%i"
0
votes

I know its too late to answer this but i guess there is an easy way IF have eclipse and the svn plugin installed on your eclipse. Right click on the project, go to Team->disconnect. It will open a popup where you select the first option: 'Also delete the SVN meta-information from file system.' This will remove all the SVN folders automatically along with svn property files that you might forget sometimes while removing .svn folders only!

-1
votes

As an important point, if you want to run shell to delete .svn folders, you may need -depth argument to prevent find command entering the directory that was just deleted and showing silly error messages like e.g.

"find: ./.svn: No such file or directory"

To get rid of this error, you can use the find command as the following:

cd [dir_to_delete_svn_folders]
find . -depth -name .svn -exec rm -fr {} \;