I have made that journey. It is very scenic, slow but worth it. These are local trains and do not show up on most international journey planners. The fare on the Spanish side is only about 10 Euros (fares have gone up since I went) all the way from Barcelona to Latour de Carol. From there to Foix it will cost you €13,50. Tickets cannot be bought in advance, there are no reservations.
French train times in printable form on this page
A couple of points - these are local trains with no on board facilities. Take food and drink with you. At Latour de Carol, while waiting for trains, there is nothing at the station or anywhere nearby.
Other buses Barcelona - Andorra at www.alsa.es and www.autocarsnadal.com/fra/lnregular.php…
It is horribly difficult to get from Andorra into France by bus/train as there are only two buses a day from Andorra to the nearest railway station, one of which leaves at 5am.
I hope that helps.