I have a folder with lots of subfolders. Each of subfolders has different type of image files. I'm trying to rename those files by specific format. Data looks like this:
folder
\ sub1\file0.jpg
\ sub1\file1.jpg
\ sub1\file2.png
.
.
.
\ sub2\xxx.png
\ sub2\yyy.jpg
\ sub2\zzz.png
.
.
.
Desired output:
folder
\ sub1\file-01.jpg
\ sub1\file-02.jpg
\ sub1\file-03.png
.
.
.
\ sub2\file-01.png
\ sub2\file-02.jpg
\ sub2\file-03.png
.
.
.
By far, I have tried following code but it doesn't work out.
import os
dir_name = "D:/folder"
for root, dirs, files in os.walk(dir_name, topdown=False):
for file in files:
file_name = os.path.splitext(file)[0]#file name no ext
extension = os.path.splitext(file)[1]
dir_name = os.path.basename(root)
os.rename(root+"/"+file, root+"/"+"file"+"s%"+extension)