Are they fruit flies? If so:
-Keep your fresh fruit covered (so they can't lay eggs on the banana skins etc), e.g. with a cotton bag or mesh cover.
-Empty your compost regularly (especially in hotter weather, when they breed faster). You could also put banana skins (which are one of the main breeding grounds) straight in the outside compost so there is less risk of them hatching inside.
-If you do get a batch that have hatched in your compost box already, crack the lid open slightly (e.g. by propping it with something) so they can get in, and then every so often close the lid, take it outside, and release them (you may need to tap the box etc so they fly off).
-Some mini hoovers will trap any stray ones unharmed for release outside.
If they are fungus gnats (hanging around near houseplants):
-Let the soil of plants dry out between waterings.
-Cover the surface of the soil with sand.
You shouldn't have plagues of other types of flies unless you have something dead, or dog muck or something sitting around in your house or near your windows. Houseflies and bluebottles might come in individually sometimes but are better at finding their way out again than the smaller ones.