optimise the path_write method for creating the path of multiple level