Yet another way, if your shell is bash and extglob is enabled (I'm sure other shells have things like it and more) is to do something like
I'm not very comfortable with that and it will try and fail to remove subdirectories, if any, but it's a possibility.
On the find, to follow along with b0uncer and to get closer to what you were asking, you could do
Code:
find . -type f ! -name '*.txt' -execdir rm {} +
I'd leave in BrianK's '-type f' to avoid just that subdir problem and find can find negated expressions. (-execdir is just a bit of paranoia.) If recursing subdirs is a problem, there's '-maxdepth 1'. (A lot of these are GNUisms.)
Doesn't much matter, as you have your problem solved but it might be useful to others with similar issues.