Command line to delete matching files and directories recursively

Rory picture Rory · Feb 11, 2009 · Viewed 36.8k times · Source

How can I recursively delete all files & directories that match a certain pattern? e.g. remove all the ".svn" directories and the files they contain?

(Sadly DOS only)

Answer

JMD picture JMD · Feb 11, 2009

Since you're looking for a DOS solution, last week's post was almost identical and the consensus was:

Command line tool to delete folder with a specified name recursively in Windows?

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

or

for /f "usebackq" %d in ("dir .svn /ad/b/s") do rd /s/q "%d"

Actually, SVN also gives you the option to export a working directory without the .svn/_svn directories.

Afterthoughts, three years later: I think the reason people end up needing to recursively delete the .svn/_svn folders is because they've directly copied their local working copy to a new location in order to do a folder comparison of their modified version compared to a clean export, i.e. after something goes awry with the modified local working copy. (At least that's why I've needed it. It's definitely easier/faster to just use 'svn export' when that's possible.)