0
import os


def rename_files():
    file_list = os.listdir(r"file directory")
    print(file_list)
    for file_name in file_list:
        os.rename(
            file_name,
            file_name.translate(str.maketrans("","", "0123456789")
       )

rename_files()

I keep getting a syntax error at the last line of the code. It doesn't give me any details, I just get a popup saying "invalid syntax" and it highlights the rename_files in red. I tried running it without the line and it throws the same error. A little new to coding so be gentle haha.

smottt
  • 3,272
  • 11
  • 37
  • 44

1 Answers1

0
import os
def rename_files():
    file_list = os.listdir(r"file directory")
    print(file_list)
    for file_name in file_list:
        os.rename(file_name, file_name.translate(str.maketrans("","", "0123456789")))
rename_files()

try this

Roy Holzem
  • 860
  • 13
  • 25