Traverse the segments sequentially, creating nested maps or objects. A pseudocode approach:
Moving files from a subfolder to a top-level directory can be done through several manual and automated methods. filedot to folder top