I have recently received several e-mails and comments about fruit flies in the compost pile, and have had several clients asking about the same issue.
Fruit flies can certainly crop up in the compost pile, and you can look here at a previous post for some tips on controlling them, but more often than not the issue is not fruit flies, but a little critter called the Fungus Gnat.
I wish they had a different name, because there is something about "Fungus Gnat" that seems to cause immediate panic and loathing in those who hear it for the first time: clients generally repeat "Fungus gnats!" in a tone of voice that I think more properly reserved for discovering that one's compost pile is infested with, say, zombies, or crocodiles, or possibly flesh-eating bacteria. Butterflies, which cause far more garden damage than ever dreamed of by the lowly fungus gnat, are met with coos and smiles and calls to the children to "come see the pretty butterfly," while the announcement of fungus gnats is invariably greeted with, "how do I annihilate them and all their descendants unto the seventh generation?"
But I digress.
Fungus gnats are slimmer than fruit flies, very small with black bodies and tiny, generally silvery wings. In the compost pile, you'll often see them clustering on the surface of the pile, and sometimes running on the container surfaces. They are attracted to moisture and rotting material, which explains their presence in the compost pile.
They cause no damage to the compost, or to humans, and are strictly a nuisance rather than a problem. As with most insect problems in the compost pile, the truly effective solution is to turn the pile frequently. You could eliminate them from your compost by letting the pile dry out, or by spraying toxic chemicals, but neither of these comports with the successful production of useful compost. Frequent turning will somewhat disrupt their life cycle, and just generally make life a bit rough on them.
I have been told that the use of coffee grounds in the compost pile will greatly reduce or eliminate the presence of fungus gnats, but I know of no scientific literature that verifies the claim. On the other hand, coffee grounds are great for compost, I use lots of them, and I rarely have much of an issue with fungus gnats, so there may be something to it.
So, if you have fungus gnats, turn the pile frequently, don't even think about spraying anything, try using coffee grounds, and be thankful you don't have zombies.