According to the University of California Cooperative Extension, flies introduce fresh bacteria to your compost, which assists in faster waste decomposition. However, flies certainly don't play a Good Samaritan role in your compost pile; they're after smelly decomposing waste, such as food scraps and cow manure, and before you know it, they can get out of hand, especially if you don't maintain your compost regularly. Multiple fly species, including soldier flies, horse flies, houseflies and fruit flies, may inhabit your compost at any time in the form of eggs, larvae (maggots) and adults. Focus your efforts on proper compost maintenance and you should see a marked decrease in flies.
Aerate your compost to increase microbial activity from oxygen-loving bacteria. Scoop the waste from the center of the pile or bin, shifting it to the outside edges with a manure fork. Gather waste from the edges of the heap and move it to the center of your pile. Repeat this aeration process at least once weekly to ensure adequate microbial activity.
Inspect your compost for fly larvae in the form of wriggling, white or gray maggots of various sizes. Don a pair of rubber gloves and pick up any maggots that you find. Gather them in a plastic cup or bucket. Dump them out on the bare ground or in a bird feeder to provide your birds with a tasty snack. Repeat this process until you no longer see any fly larvae in your compost.
Squeeze a handful of compost waste to check the moisture level of your decomposing compost; if you can wring out more than two drops of liquid, then you've got a moisture problem. Add carbon-rich waste, such as straw, sawdust or shredded newspaper to your pile or bin. Shift the fresh waste into the center of the compost to soak up the extra moisture and discourage smelly, fly-attracting, anaerobic decomposition.
Add only mild food scraps, such as fruit peels, old vegetables and dried bread, to your compost. Avoid smelly foods, such as bones, meat and dairy products, which attract flies in droves. Bury all food scraps beneath 3 to 4 inches of carbon-rich waste, such as sawdust, which limits odors and keep the flies from laying eggs on it.
Sprinkle grass clippings or freshly cut hay on your compost to provide most of the nitrogen content. Try not to use fresh manure in your compost, since it provides a common location for fly eggs.