Created
May 11, 2020 16:16
-
-
Save kyletaylored/fee41bad92eb8bdea54cf65543e9997d to your computer and use it in GitHub Desktop.
Python renaming script (specific use case)
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
# Python 3 code to rename multiple | |
# files in a directory or folder | |
# importing os module | |
import os | |
from shutil import copyfile | |
# Function to rename multiple files | |
def main(): | |
for count, filename in enumerate(os.listdir(".")): | |
if (filename.find(".jpg") > 0 or filename.find(".jpeg") > 0 or filename.find(".jpeg") > 0): | |
print(filename) | |
id = filename.split("-")[1] | |
ext = filename.split(".")[1] | |
src ='./'+ filename | |
dst ='./processed/'+ id + '.' + ext | |
# rename() function will | |
# rename all the files | |
copyfile(src, dst) | |
# Driver Code | |
if __name__ == '__main__': | |
# Calling main() function | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment