Implement optional extension removal in path.basename