Create a function which replaces the last instance of the path
component.