How to remove .svn files under Windows

One of the common tasks while developing software is removing subversion files. It is a good practice to remove .svn files before sending code to your client to give him clean solution with no additional information on how was your code managed. It is easier for client to manage received code on his own when he doesn’t need to remove .svn files that were left by you.

To remove .svn files just enter this code into a bat file – let’s say remove-svn.bat.

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

Next step is to place remove-svn.bat in the root directory of your project and run it.
That’s all.

If you are interested in what this script does behind the scenes here is the answer.

for /f is a loop command that conditionally performs command against each file item. tokens and delims are the options which specify which numbered item to read and what is the delimiter character from each line.

Next there is a %%i parameter which represents a file item.
dir command displays a list of files and subdirectories in a directory. /s argument is set to display files in a directory and subdirectories. /b is set to for the command to use bare format which doesn’t display heading information or summaries. Next an /a argument is set with d option that lists only directories. At the end we have *svn pattern which specifies what items we want to process.

rd command deletes directory. /s flag removes all directories and files and a given directory. /q when set indicates a quiet mode – script doesn’t ask if it’s ok to remove a directory tree.

2 Responses to "How to remove .svn files under Windows"

  1. Krzysiek says:

    A different approach to this problem is you can get it directly from SVN using “export” instead “checkout” command.
    It works on any operating system and you don’t need an external solution :)

    P.S. There’s a time issue of course – if a lot of source files have to be exported probably the script would have done it faster.

    Reply
    • itcuties says:

      Accurate observation Krzysiek! We wonder what would the difference be… We have to find some big SVN repository to test it :)

      Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>