Invalid syntax message with no apparent error

0

I'm trying to rename a folder that has a set of files, I want to remove all the digits from the file names. But when I try to run the code the error message appears: "invalid syntax", pointing specifically to the os module. Can anyone tell me the reason for the error and how can I fix it? Here is the code:

import os 
def rename_files():
    #(1) pegue os nomes dos arquivos da pasta 
    file_list = os.listdir(r"C:\Projetos\arquivos") 
    #print(file_list)
    saved_path = os.getcwd()
    print("Curret Working Directory is "+saved_path)
    os.chdir(r"C:\Projetos\arquivos")
    #(2) para cada arquivo, renomeie o nome do arquivo
    for file_name in file_list:
        print("Old Name - "+file_name)
        print("New Name - "+file_name.translate(None, "0123456789")
        os.rename(file_name, file_name.traslate(None, "0123456789"))
    os.chdir(saved_path)
rename_files()
    
asked by anonymous 02.10.2017 / 22:39

1 answer

2

The error is on line 12, you did not close the print function's parentheses:

The correct one would be:

import os 
def rename_files():
    #(1) pegue os nomes dos arquivos da pasta 
    file_list = os.listdir(r"C:\Projetos\arquivos") 
    #print(file_list)
    saved_path = os.getcwd()
    print("Curret Working Directory is "+saved_path)
    os.chdir(r"C:\Projetos\arquivos")
    #(2) para cada arquivo, renomeie o nome do arquivo
    for file_name in file_list:
        print("Old Name - "+file_name)
        print("New Name - "+file_name.translate(None, "0123456789"))//O erro estava aqui
        os.rename(file_name, file_name.traslate(None, "0123456789"))
    os.chdir(saved_path)
rename_files()
    
02.10.2017 / 23:00