79224655

Date: 2024-11-25 21:38:13
Score: 1.5
Natty:
Report link

I applied @jasonharper's comment:

The questionmark wasn't the problem, instead I tried changed dirnames while iterating through filenames and changing them.

Working code:

import os
import re

def changefilename():
    dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..",".."))
    for root, dirs, files in os.walk(dir_path):
        for dir in dirs:
            new_dir = re.sub(r"([^\?]*)\?(.*)", r"\1\2", dir)
            print(dir, root, new_root)
            os.rename(os.path.join(root, dir),os.path.join(root, new_dir))

changefilename()
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @jasonharper's
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: brathenne