I want to copy all the images in different folders into one folder. But the issue I am facing is files in different folders have same names e.g
Folder: A123 Front A123 Black.jpg , A123 Pink.jpg , A123 Red.jpg
Folder: A123 Back A123 Black.jpg , A123 Pink.jpg , A123 Red.jpg
What I want to achieve is all files in one folder and named something like,
A123_1.jpg ,A123_2.jpg , A123_3.jpg , A123_4.jpg , A123_5.jpg , A123_6.jpg
Note, A123 is product code and so I want Product code with numbr of images with that product code appended with underscore.
These are in 1000s and in sub sub directories, I have simplified it for convenience.
I have written following code , to go into directories and sub directories.
import os
def replace(folder_path):
for path, subdirs, files in os.walk(folder_path):
c=len(files)
for name in files:
if 'Thumb' in name:
continue
file_path = os.path.join(path,name)
print(file_path)
new_name = os.path.join(path,strname)
os.rename(file_path,strname)
c-=1
print('Starting . . . ')
replace('files/GILDAN')
But I am not sure how should be renaming.