from pathlib import Path TASK_NAME = Path().absolute().name i = 1 while True: old_in = Path(f"{i}.in") old_out = Path(f"{i}.out") if (not old_in.exists()) and (not old_out.exists()): exit() new_folder = Path(f"Test{i:02}") new_in = new_folder / f"{TASK_NAME}.inp" new_out = new_folder / f"{TASK_NAME}.out" new_folder.mkdir() old_in.replace(new_in) old_out.replace(new_out) i += 1