import os from pathlib import Path import traceback paths = [] paired_paths = [] counter = 0 try: for path in Path('input/').rglob('*'): counter += 1 path = str(path) oldext = os.path.splitext(path)[1] os.rename(path, "shame/" + str(counter) + oldext) path = "shame/" + str(counter) + oldext paths.append(str(path).replace("\\", "/")) except Exception as e: print(traceback.format_exc()) input() for i in range(0, len(paths), 2): if i+1 > len(paths): paired_paths.append([paths[i]]) else: paired_paths.append([paths[i], paths[i+1]]) print(paired_paths)