Had exactly that problem. There were hundreds of flies in the loft, I think they are called Flesh flies.
Didn't take long to kill them. Sprayed a couple of tins over a seven day period, Sealed the hatch with tape to exclude light source. Haven't yet found the rat though