i want to rename all the files in a folder. Each filename will change from "whateverName.whateverExt" to "namepre+i.whateverExt". e.g. from "xxxxx.jpg" to "namepre1.jpg"
i try the modify code from (Rename files in sub directories), but fail...
import os
target_dir = "/Users/usename/dirctectory/"
for path, dirs, files in os.walk(target_dir):
for i in range(len(files)):
filename, ext = os.path.splitext(files[i])
newname_pre = 'newname_pre'
new_file = newname_pre + str(i) + ext
old_filepath = os.path.join(path, file)
new_filepath = os.path.join(path, new_file)
os.rename(old_filepath, new_filepath)
Can someone help me? THX!!!