How rename the images in folder
The Easiest and Cleanest, Iterate through all the files and rename with index.
import os
os.getcwd()
collection = "C:/darth_vader"
for i, filename in enumerate(os.listdir(collection)):
os.rename("C:/darth_vader/" + filename, "C:/darth_vader/" + str(i) + ".jpg")
This shows how to sequence all files in a directory. For example, if the directory has 50 files, it will rename them 0-49. You can also loop through your folder names using some iterator as follows:
import os
for dirname in os.listdir("."):
if os.path.isdir(dirname):
for i, filename in enumerate(os.listdir(dirname)):
os.rename(dirname + "/" + filename, dirname + "/" + str(i) + ".bmp")
You could use os.walk:
for root, dirs, files in os.walk(folder):
for i,f in enumerate(files):
absname = os.path.join(root, f)
newname = os.path.join(root, str(i))
os.rename(absname, newname)
This should do exactly what you wanted.