There are foods I avoid because they make me hungrier, more likely to overeat crap and crave sugar, so just not buying them is the only option!
You do have to use your willpower. It's like a muscle, the more you use it, the easier it is. Being healthier has to be a bigger motivation than eating that cake/bread/choc bar.
For me, I'd rather use my calories to be FULL as I hate being hungry. So I'd prefer a nice meal with loads of veg than a doughnut.
You're in charge. Having a craving doesn't mean you have to have it. Ask yourself at the time, is the short term, short lived enjoyment of eating the cake more important than the long term goal of being healthy?
The crap food soon actually stops being a treat, because it just makes you feel shit.
I really enjoy being proud of my eating habits, rather than being disgusted with myself.
As humans, we're wired for short term satisfaction so you have to keep reminding yourself of the long term.
I find most people know how to be healthier. They know how to lose weight, they know what foods aren't great. But you have to look at why you're not making those choices.
Best of luck.