I think they have to go back about 1200 years unless somebody has a boy real soon.
Whole big bunches of the royal lines ran out in the 1800s. I've looked through the primary genealogies, and it looks like they were all hit particularly hard by tuberculosis.
I'm not sure if you are referring to Japan or France. The French royal family had a lot of members who died young, and tuberculosis seems to have been a major reason. There may be descendants of Louis Philippe around (I think Charles X's grandson, who would have become Henry V if they had restored the monarchy after the fall of Napoleon III, died childless).
King Juan Carlos of Spain is also descended from Louis XIV but perhaps his ancestor renounced any rights to the throne of France for his descendants, when he became Philip V of Spain in 1700.