I have a few directories, some with a depth of 3, which contain mixed file types. What I need to do is to rm -rf all the subdirectories that do not contain filetype foo.
Is this achievable with find somehow?
I do know that I can use find like this:
find . ! -name '*.foo' -delete
to delete all files within the directories that do not contain any file of type *.foo.
Now, how can I use this, to not only delete all unwanted files, but all directories and subdirectories which do not contain *.foo?

/a/b, andbhas no*.foofiles, but/a/b/chas*.foofiles, obviously we don't want to runrm -rf /a/b, right? In this case, I don't thinkrm -rfis the right approach, maybe we need something likerm dir/*; rmdir dir. – Mikel Mar 1 '11 at 3:20some.fooandsome.bar, should it be deleted? Your question is not clear in this respect. – Gilles Mar 1 '11 at 23:31