find command:https://www.howtouselinux.com/post/find-file-by-name-in-linux
find . -type f ( -iname "*.txt" ! -iname "foo.txt" )
find . -type f ( -iname "*.txt" ! -iname "foo.txt" ) -delete
To select folder or dirs use -type d, in this example, find all folders and ignore foo and bar folder :
find . -type d ( ! -iname "foo" ! -iname "bar" )
find . -type d ( ! -iname "foo" ! -iname "bar" ) -execdir rm -rfv {} +