Nov-08-2016, 06:45 PM
Hello, I am just starting to learn Python with the Python 3.5.2 version. I am supposed to start with a really easy task, renaming all the files in a folder. (Taking out the numbers out of the filenames.)
But I always get a Syntax-Error message (Invalid Syntax). Can someone please help me? I don't know what is wrong!
line 13: os apparently is a syntax error
But I always get a Syntax-Error message (Invalid Syntax). Can someone please help me? I don't know what is wrong!
line 13: os apparently is a syntax error
import os def rename_files(): #(1) get file names form a folder file_list = os.listdir(r"C:\Users\harley\Documents\Python\Introduction\rename") #print(file_list) saved_path = os.getcwd() print("Current Wokring Directory is", saved_path) os.chdir(r"C:\Users\harley\Documents\Python\Introduction\rename") #(2) for each file, rename filename for file_name in file_list: os.rename(file_name, filename.translate("0123456789") os.chdir(saved_path) rename_files()