A blaze burning in foothills west of Yosemite National Park destroyed dozens of structures and forced thousands to flee Gold Rush-era towns but fire crews have been able to stop it from reaching a threatened community on the foothills of the Sierra Nevada.