I am trying to rename a list of files with names for example: This is File 132 (file no 132)
to This is File 132
. So what I want is to replace (file no *)
with ''
. How to implement this *, where ultimately I want to replace this particular place in the name in every file. This is the code I have written so far. Any help is appreciated.
import os
directoryname = "/media/username/New Volume/"
listFiles = os.listdir(directoryname)
print(listFiles)
for i in listFiles:
os.rename(os.path.join(directoryname, i), os.path.join(directoryname, i.replace('(file no 132)', '')))
listFiles = os.listdir(directoryname)
print(listFiles)