Found a great way... Fill a wide mouth jar or container half full of Cider Vinegar (must be cider, others won't work) Put in a few drops of dishwasher fluid Fill the remainder with water. The soap will create bubbles, let them come all the way to the top. The fruit flies will be attracted to the Cider odor, and get stuck in the bubbles. After a day or two, pour off the top, add a couple drops of soap, and refill with water so the bubbles come to the top.
Take out the rotten food early and swat them whenever you get a chance. My mom uses a fly swatter with a metal handle because plastic bends whenever you swing it. I usually swat them with hands, but to do that you have to wait until the fly comes to you and when it gets close enough move very quick to swat it. I would recommend using a fly swatter rather than your hands. You can also use honey to trap flies, but I only got that from the saying, "You don't catch as many flies with vinegar than with honey."