0
I am trying to rename a folder that has a set of files, I want to remove all digits of the names of the files. But when I try to run the code the error message appears: "invalid syntax", pointing specifically to the module os. Can anyone tell me the reason for the mistake and how to fix it? Follow 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()
Can you put the full error message in the question? And how is this code running?
– Woss
This is the complete error message. I run the program and open a window with the phrase "invalid syntax" I use idle to write, I don’t know if it influences how messages are shown.
– Alineat
@Andersoncarloswoss , I used another online editor and wrote the message: "Traceback (recent call last): File "python", line 13 os.Rename(file_name, file_name.traslate(None, "0123456789") Syntaxerror: invalid syntax"
– Alineat