Look up pathfinding algorithms, very common in games.
So you are in square 1 and you need to get to finish square. What you want is something like this:
1. Check if the square is the finish square. If it is then return True. If not go to step 2.
2. For every neighbour square(up, down, left and right) check if there is no wall or that you haven't already visited that square. If you have already been in every neighbour square or cant move there because of a wall return False meaning that this was a dead-end.
3. Call this function to every neighour square that you can move and if one of them returns True "paint" or mark this current tile as the right path.
Sooner or later you will get a string of functions each returning True and marking some square as the right path. You need some kind of a list to hold coordinates of the squares you have already visited.