BEIJING — Ding Fei, a truck driver from rural China, was thrilled to find a school in a crowded migrant neighborhood where his 7-year-old daughter might flourish. Finally, he thought, she could learn to read and write, and maybe even have a shot at becoming a doctor or nurse, as her mother hoped.

Then the government intervened. On a bitterly cold day last month, Beijing officials informed parents and teachers that the school was unsafe and illegal. Within hours, the school, which served more than 200 students from rural areas, had been shut down and marked for demolition.

Beijing is in the midst of one of the most aggressive campaigns in recent history to drive out rural migrants, evicting thousands from their homes and leveling neighborhoods in scenes that evoke the devastation of war. The crackdown has also increasingly taken aim at dozens of schools that have sprung up to serve migrant families, advocates say, targeting children who already live on the margins of society.

These schools exist in an educational gray zone, often operating without licenses and with teachers who — like the families of their students — do not have official permission to live and work in Beijing. Educators say that more than a dozen schools have been shut down or demolished this year, often with just a few days’ notice, cutting off access to education for as many as 15,000 children. Many of these children are under 12.