Renaming directories in order to preserve the order