Last active
July 14, 2020 13:26
-
-
Save noelje/4e67b6d9ed568daac1f4c0ab29bd3a1c to your computer and use it in GitHub Desktop.
A python script to rename all the files (eg. images) in an order (eg. 1.png, 2.png)
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
print("Running Python app...") | |
# renaming files | |
# Pythono3 code to rename multiple | |
# files in a directory or folder | |
# importing os module | |
import os | |
# Function to rename multiple files | |
def main(): | |
for count, filename in enumerate(os.listdir(".")): | |
dst = str(count) + ".jpg" | |
src = filename | |
dst = dst | |
# rename() function will | |
# rename all the files | |
os.rename(src, dst) | |
# Driver Code | |
if __name__ == '__main__': | |
# Calling main() function | |
main() | |
# https://www.geeksforgeeks.org/rename-multiple-files-using-python/#:~:text=In%20Python3%2C%20rename()%20method,Syntax%20for%20os. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment