ubuntu remove all folders but keep some

C++
find ./myfolder -mindepth 1 ! -regex '^./myfolder/test2\(/.*\)?' -delete
Source

Also in C++: