Command to recursively remove all .svn directories on Windows

WindowsSvnCommand Line

Windows Problem Overview


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?

Windows Solutions


Solution 1 - Windows

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"

Solution 2 - Windows

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

Solution 3 - Windows

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

Solution 4 - Windows

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.

Solution 5 - Windows

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

Solution 6 - Windows

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"

Solution 7 - Windows

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!

Solution 8 - Windows

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 {} \;

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
Questionuser489041View Question on Stackoverflow
Solution 1 - WindowsAjit VazeView Answer on Stackoverflow
Solution 2 - WindowsBobby CannonView Answer on Stackoverflow
Solution 3 - WindowsGreg HewgillView Answer on Stackoverflow
Solution 4 - Windowsvisar_uruqiView Answer on Stackoverflow
Solution 5 - WindowsRolandView Answer on Stackoverflow
Solution 6 - Windowsuser14029352View Answer on Stackoverflow
Solution 7 - Windowsfresh learnerView Answer on Stackoverflow
Solution 8 - WindowsfatihkView Answer on Stackoverflow