Function to build path