for i in range(99):
change_i = str(i).zfill(4)
print(change_i)
""" Output is :
0000
0001
0002
0003
...
0098
"""
for i in range(99):
change_i = str(i).zfill(5)
print(change_i)
""" Output is :
00000
00001
00002
00003
...
00098
"""
Source of problem :
I wanted to use it sorted(os.listdir(parh)) To read files in the order of their names , But because the name is not unified , So it didn't read as expected
Next, the numeric part of the file name is uniformly named as four digit
import os
path = "/data/cta/deal-with-dataset-b-v1/dicom_hessian"
for file in os.listdir(path):
num = file.split(".")[0].split("_")[-1]
filename_change = "dicom_hessian_" + num.zfill(4) + ".jpg"
os.rename(os.path.join(path, file), os.path.join(path, filename_change))
So far, the problem has been solved ~