77

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?

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
user489041
  • 27,916
  • 55
  • 135
  • 204
  • 4
    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 Feb 03 '11 at 17:47
  • 1
    You might also be interested in the svn export command (http://svnbook.red-bean.com/en/1.0/re10.html), which copies a directory to another location, but without all the .svn directories. – JB Nizet Feb 03 '11 at 17:50
  • @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 unclear – Sander Rijken Feb 03 '11 at 17:52
  • possible duplicate of [Removing .svn files from all directories ](http://stackoverflow.com/questions/1301203/removing-svn-files-from-all-directories) – Sander Rijken Feb 03 '11 at 17:53
  • @Sander Rijken: thanks, but since the OP asked for a command, and I didn't have one to propose, I considered my answer as a workaround rather than a real answer. – JB Nizet Feb 03 '11 at 17:57
  • Why did this question have a -1? – user538442 Feb 03 '11 at 18:52
  • I think the reason is that the question has been asked before. That's the reason for my close as duplicate vote at least.. – Sander Rijken Feb 03 '11 at 19:23
  • 1
    @user538442 Please consider changing your accepted answer – Brian Webster May 01 '17 at 23:52

8 Answers8

178

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"
izilotti
  • 4,757
  • 1
  • 48
  • 55
Ajit Vaze
  • 2,686
  • 2
  • 20
  • 24
  • 1
    Thanks a lot. thats what i exactly want. i disconnected from my svn repository for some reason and was having no time to make R&D for this reason. now i use Filezilla to upload full project without any .svn folder with this command. again thanks – M K Garwa Sep 11 '13 at 19:13
  • Thanks for this. Greatly appreciated. I was given a folder tree with .svn but do not actually use it. Searching in Win for .svn (regardless of show hidden files on or off) returned zero results. The command line prompt did the trick! – Rid Iculous Oct 12 '13 at 23:29
  • Awesome. Most simple and effective way. Searched in Google for "windows cmd remove folders recursively" but I actually wanted .svn deletion, love when the search engine corrects my wish to this point :) – Armfoot Mar 25 '14 at 04:52
  • 1
    Thanks! Tip: to open a cmd already in the desired folder shift+click on the folder from windows explorer and choose "open command window here". on cmd.exe you can just right click with the mouse to paste the 2nd command @Ajit/@izilotti shared. Works like a charm (win7) – Jorge Orpinel Pérez Apr 27 '14 at 05:29
  • This page explains how to add the command to the explorer's context menu. – SJuan76 Jun 29 '20 at 10:13
47

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
Sander Rijken
  • 21,376
  • 3
  • 61
  • 85
Bobby Cannon
  • 6,665
  • 8
  • 33
  • 46
  • Note: If you have Paths with more than 260 characters, you'll get a RemoveItem PathTooLongException. – bluelDe Feb 14 '16 at 12:10
31

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

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 5
    This may not be what he is looking for. I wanted the same thing so I could check in some already modified code into another SVN location. – Bobby Cannon Feb 03 '11 at 17:47
  • you can do that after an `svn export` – Sander Rijken Feb 03 '11 at 17:48
  • 3
    That command does not take the existing files from your disk, instead it creates a copy from what's currently the most recent version in your repository. You should've used `svn export WCPath NewPath` – Sander Rijken Feb 04 '11 at 18:03
  • 4
    'svn export' works well if you have access to the original repository. Sometime I receive code dumps that contains .svn directories that point to repositories that I cannot access. In this case, one of the batch file or powershell answers is the way to go. – Kevin Jan 23 '13 at 16:54
  • 8
    This doesn't answer the actual question. Eg I received a folder tree, but do not use SVN. So the "export" command is not available to me. – Rid Iculous Oct 12 '13 at 23:25
  • This does not work if the .svn directories are created by an older version of svn. This is probably the case for the OP, and the reason why he wants to remove the .svn directories. This was also my problem. – Roland Aug 26 '14 at 08:32
  • as others have said, this is not even an answer. – jheriko Nov 08 '14 at 18:38
  • The OP tagged the question for svn, and made no indication that aa non-svn solution was needed. This is the "correct" way if you're using svn tools. So I *do* think it's a good answer, it's the *question* that is bad. – Ben Oct 23 '15 at 13:42
11

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.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
visar_uruqi
  • 2,484
  • 1
  • 23
  • 20
10

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

Roland
  • 4,619
  • 7
  • 49
  • 81
1

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"
fcdt
  • 2,371
  • 5
  • 14
  • 26
0

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!

fresh learner
  • 467
  • 4
  • 22
-1

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 {} \;
fatihk
  • 7,789
  • 1
  • 26
  • 48