Windows batch file to delete .svn files and folders

In order to delete all “.svn” files/folders/subfolders in “myfolder” I use this simple line in a batch file:

FOR /R myfolder %%X IN (.svn) DO (RD /S /Q "%%X")

This works, but if there are no “.svn” files/folders the batch file shows a warning saying: “The system cannot find the file specified.”
This warning is very noisy so I was wondering how to make it understand that if it doesn’t find any “.svn” files/folders he must skip the RD command.

  • Run an external program upon git add a specific file with the specific file as a parameter
  • My batch script only works the second time
  • Write a batch script to edit text in a .cs file
  • Git add submodules to super project from existing repos
  • .cmd Batch file not pushing my local .git repo to GitHub
  • Automatically cache git credentials from a Windows batch script?
  • Usually using wild cards would suffice, but in this case I don’t know how to use them, because I don’t want to delete files/folders with .svn extension, but I want to delete the files/folders named exactly “.svn”, so if I do this:

    FOR /R myfolder %%X IN (*.svn) DO (RD /S /Q "%%X")

    it would NOT delete files/folders named exactly “.svn” anymore.
    I tried also this:

    FOR /R myfolder %%X IN (.sv*) DO (RD /S /Q "%%X")

    but it doesn’t work either, he deletes nothing.

  • SVN load new repository
  • “git svn clone”: Author not defined in users.txt?
  • How to fix “containing working copy admin area is missing” in SVN?
  • converting messy svn repository to git
  • Handling renames: svn vs. git vs. mercurial
  • Subversion to Git: Clone creating branches?
  • 8 Solutions collect form web for “Windows batch file to delete .svn files and folders”

    you can try

    FOR /R myfolder %%X IN (.svn) DO (RD /S /Q "%%X" 2>nul)
    for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *svn') do (rd /s /q "%%i")

    Something like that using find :

    rm -rf `find . -name ".svn" -type d`


    I know this is for linux (I read bash instead of batch). I’m leaving it here to help Linux users that would randomly end-up here 🙂

    Actually, this answer is from Jesper Rønn-Jensen at

    I thought it was so much easier I’d share. I’m converting several projects from .SVN to .GIT, so this was great. It adds a menu item to Explorer so you can remove the folders. Create a .reg file, and import it.

    enter image description here

    Windows Registry Editor Version 5.00
    ; Running this file will give you an extra context menu item in Windows Explorer
    ; "Delete SVN folders"
    ; For the selected folder, it will remove all subfolders named ".svn" and their content
    ; Tip from
    ; Enrichened with comments by Jesper Rønn-Jensen ( )
    @="Delete SVN Folders"
    @="cmd.exe /c \"TITLE Removing SVN Folders in %1 && FOR /r \"%1\" %%f IN (.svn) DO RD /s /q \"%%f\" \""

    Bizarre sidenote: if I use

    FOR /R . %%X IN (*.svn) DO (echo "%%X")

    instead of

    FOR /R myfolder %%X IN (.svn) DO (RD /S /Q "%%X")

    not only does it list all directories ending in .svn, it lists ALL THEIR CONTENTS as well. This is a BUG in the For command, it gave me an expansion where I gave it no wild card. Very strange.


    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. Your done.

    Thanks to

    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.

    Here is my favorite, its simple and compact:

    find ./ -name ".svn" | xargs rm -Rf


    To delete all svn files on windows

    for /d /r . %d in (.svn) do @if exist "%d" rd /s/q "%d"

    .svn is the folder name

    Git Baby is a git and github fan, let's start git clone.