views:

5306

answers:

6

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)

A: 

On *nix or Cygwin:

find -name .svn -print0 | xargs -0 rm -rf
greyfade
+3  A: 

Something like this may do the trick, but of course be careful with it!

find . -name ".svn" -exec rm -rf {} \;

Try something like this first to do a dry run:

find . -name ".*" -exec echo {} \;

Note that the empty braces get filled in with the file names and the escaped semicolon ends the command that is executed (starting after the "-exec").

dreeves
This worked perfectly for me. Thanks!I needed to remove all "CVS" directories, so I ran a find . -name "CVS" -exec rm -rf {} \;
cmcculloh
+5  A: 

Is this Unix or Windows? On Unix, an easy solution is

find . -name '.svn' -type d | xargs rm -rf

This searches recursively for all directories (-type d) in the hierarchy starting at "." (current directory), and finds those whose name is '.svn'; the list of the found directories is then fed to rm -rf for removal.

If you want to try it out, try

find . -name '.svn' -type d | xargs echo

This should provide you with a list of all the directories which would be recursively deleted.

antti.huima
I upvoted because I was looking for the same question, on Win32, but with gnutils installed -- so this worked perfectly for me. Man, pure-DOS is so crazy!
Michael Paulukonis
+3  A: 

If your files are in subversion, then doing an export from the repository will give you a directory tree with the .svn files and any other cruft removed.

anon
ah, _that's_ how you do it!
Rory
+11  A: 

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

http://stackoverflow.com/questions/521382/command-line-tool-to-delete-folder-with-a-specified-name-recursively-in-windows/521433#521433

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, apparently TortoiseSVN also gives you the option to export a working directory without the .svn/_svn directories.

JMD
"Actually, apparently TortoiseSVN also gives you the option to export a working directory without the .svn/_svn directories." I believe that is a feature of svn itself (`svn export`) not just TortoiseSVN, so any other client can do it too.
MatrixFrog
A: 

If you want to copy it without exporting and eliminating the .svn from the projects, you shold use the /EXCLUDE option from XCOPY.

Like this:

xcopy /S/Q/EXCLUDE:svn.excludelist [path_from] [path_to\]

Observe the "\" (backslash) on the [path_to]. It determines that it's an output directory, so, xcopy will not question if it's a file or a directory.

The svn.excludelist is a text file containing the patterns to ignore on copy separated by line.

For Example:

.svn
.svn\
\.svn\
.obj
.o
.lib
\src\

And so on...

Cheapshot