I'm renaming files and saving in a new directory using this code:
import os
# Function to rename multiple files
def main():
i = 0
path="./path/"
for filename in os.listdir(path):
my_dest ="Layer" + str(i) + ".dcm"
my_source =path + filename
my_dest = "./Layers/" + my_dest
# rename() function will
# rename all the files
os.rename(my_source, my_dest)
i += 1
# Driver Code
if __name__ == '__main__':
# Calling main() function
main()
But it's turning the files into "0, 1, 2...9, 10", and when the directory order by name, th files go by "0, 1, 10, 101, 102...11, 110...2" messing up all the order.
I tried to search for a way to rename like "001, 002, 003, 004... 010... 099, 100" so it will stay in order, but the answers are in c++, r and all and I don't know this languages, so if there's a answer in python I could use some help.