[Python] Por que se eu renomear a pasta os arquivos dentro dela mudam? [fechada]

Discussão em 'Python' iniciado por Stack, Dezembro 6, 2024.

  1. Stack

    Stack Membro Participativo

    Estou usando o lubuntu 17 e tinha uma pasta chamada images com alguns arquivos dai tava tentando renomear esses arquivos com esse programinha em python:

    import os
    import re


    def repl(match):
    dic = {"4": "0", "5": "1", "6": "2", "7": "3", "Q": "4",
    "J": "5", "K": "6", "A": "7", "2": "8", "3": "9"}
    print(match.group()[0], dic[match.group()[0]])
    return "{}.".format(dic[match.group()[0]])


    for name in os.listdir("pasta"):
    old_file = os.path.join("pasta", name)
    new_file = os.path.join("teste", re.sub(
    r"[A-Z0-9][.]", repl, name))
    os.rename(old_file, new_file)


    Agora se eu renomear a pasta teste para images de novo os arquivos ficam trocados, vejam: [​IMG] [​IMG] [​IMG]

    por exemplo o 9 vira 3. Como eu resolvo isso?

    Continue reading...

Compartilhe esta Página