Trying to write simple code to do something like this will be "fragile"---meaning that you have to be very careful in how you specify things.
Here's a simple example of the kind of thing that might work, but it's just using rm for files. TEST any code before actually using on real data.
Code:
rm $(ls|egrep -v "(file1|file2)") ##removes everything except file1 and file2