Last active
July 22, 2019 07:04
-
-
Save arthurarty/da2bd8a07caa112302b45d4d0057a216 to your computer and use it in GitHub Desktop.
Rename files in a given directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def rename_files(folder_name, new_file_name): | |
"""Rename images in a folder""" | |
i = 0 | |
dir = "./" + folder_name | |
for filename in os.listdir(dir): | |
dst = new_file_name + str(i) + ".jpg" | |
src = folder_name + "/" + filename | |
dst = folder_name + "/" + dst | |
os.rename(src, dst) | |
i += 1 | |
if __name__ == '__main__': | |
rename_files("16", "boy_16_") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment