On Unix or Mac:
How do you delete all files NOT of a specific type. Or How to copy all files of a specific type with the containing folder.
Use find, e.g. to delete all files which are not .txt files:
WARNING: use this kind of command with care as it's easy to delete a lot of files unintentionally. Do a "dry run" first if you're not confident, e.g. to preview the above command: