I've just started playing Dwarf Fortress, and I'm noticing that at least 75% of my population (now 46 dwarfs) are complaining about flies. I don't see them anywhere, although I do at one point remember seeing a 'swarm of flies'.
Google tells me that it's because I'm not putting my food in bins/barrels/containers but look at my stockpiles ALL I see are barrels, I started cranking them out specifically because of this.
I had thought perhaps that they just had a really long memory, but recent births into my population proves otherwise as the babies appear to have an issue with flies too.
Flies are Vermin, and as such, randomly spawn and despawn across the map; there's nothing you can do to prevent this behavior
What you can do is bring cats. Cats will kill the Vermin, and should reduce the incidents of your dwarves running into vermin.
A final note: dwarves are only bothered by flies if they hate flies specifically (as opposed to another of the vermin critters). It's a minor negative thought, easily counteracted by eating good food / booze, not having to sleep on the ground, etc.
Flies are attracted to dead bodies, piles of food (including unpicked crops on the farm) and pools of water.
Reasons you don't want them:
Note that they don't have the
[VERMIN_EATER] tag, so they won't actually eat your food, just buzz around it, annoy dwarves, and possibly speed up rotting.
Here is some advice on protecting against flies:
Flies are a type of above ground vermin. They are found in swarms near pools, farms with unpicked food and food stockpiles, and may cause food to rot. Since cats cannot kill flies, the best way to protect against them is to make sure food is not left outside of a container too long. Make sure you have enough barrels and bags to store your food and someone ready to pick food from farms once ready. If there's no food around outside of a container, flies will go away.
I would further suggest that you keep your food stockpile, your farms and your butcher's workshop in secluded areas. This means that if you do get flies, your dwarves are less likely to be bothered by them. Keeping the butcher's workshop in a secluded area (with a door) is a good idea anyway as butchers' workshops tend to generate miasma, which you also want to keep away from your dwarves.
They also tend to flicker in and out of visibility on the map, so if you're looking around the map whilst paused you might not see them. Narrow it down to a few places they might be, then watch those places and see if they pop up.
Can cats kill flies?
There seems to be some argument about this. As quoted above, the wiki page on flies says that cats cannot kill flies but doesn't seem to offer much explanation. However, I've not been able to find it explicitly contradicted either.
I've done some digging around and found that the
[HUNTS_VERMIN] tag (that cats have) is a bit confusing, mainly because there is no single
[VERMIN] tag that determines whether or not a creature is vermin. Instead there are lots of tags like
[VERMIN_MICRO], etc., which are overlapping and not mutually exclusive. So it probably depends on the exact implementation of that
[HUNTS_VERMIN] tag - there might be a list of all the vermin tags somewhere which it uses, or it might exclude some of them (like
[VERMIN_MICRO]) or only include some of them... hard to know.
I'm pretty certain that as in real life, birds like ducks and in fact any bird animal bought as a pet will do what a soap foundry will not in reducing flies (which I do not see on your pictures of inhabited areas; so the problem is perhaps in work areas such as the butchery/tannery/fishery if things are untended too long, or in staging areas in orchards.
I guess you're stuck building a duck shed in the orchard or killing field, right where you would have a cage trap for something else. Duck-walk the Amber Path!