How to change all files name in a specified directory

PHOTO EMBED

Mon Oct 24 2022 03:41:56 GMT+0000 (Coordinated Universal Time)

Saved by @DiegoEraso #python

import os

# Function to rename multiple files
def main():
    i = 0
    path = r"path_name"
    for filename in os.listdir(path):
        dst = str(i).zfill(4) + ".jpg"
        src = os.path.join(path, filename)
        dst = os.path.join(path, dst)
        os.rename(src, dst)
        i += 1
    return print("{} FILES COMPLETADOS".format(len(os.listdir(path))))


# Driver Code
if __name__ == "__main__":

    # Calling main() function
    main()
content_copyCOPY

https://stackoverflow.com/questions/53809771/finding-all-image-files-in-folder-and-change-their-names-with-number