Deleting all folders and sub-folders with a given name with Windows Shell

This particular script came in handy when I copied a project that was under source control with SVN and wanted to “unbind” it. The easiest way to do that is to delete all the .svn folders and sub-folders inside the project’s directory.

This could be achieved by doing a search in Windows for “.svn”, selecting all the returned directories and deleting them. But if this way is not an option, here is a scrip that will do the trick:

for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *svn') do (  rd /s /q "%%i")
  1. create a file with any text editor
  2. paste this script in
  3. save it with a .cmd extension (e.g. delete_svn.cmd)
  4. there are 2 ways to run the script:
    • from the Command Prompt
      • go to the top directory where you want to do the deletion (let’s call it working directory)
      • type [path_to_cmd_file]\delete_svn.cmd and then Enter
    • from the Windows Explorer
      • copy the .cmd file to the working directory
      • double-click on it

This should take care of recursively deleting all the directories called .svn