Skip to content

Commit

Permalink
Create sortImages.py
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinZhong authored Apr 29, 2022
1 parent 900b26b commit 492d6e3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions sortImages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import shutil

mainFolder = "main/folder/toSort"


# image name example : MRV01-003-000-002.jpg

def main():
# sort files by last code name in file name
for filenames in os.listdir(mainFolder):
if filenames.endswith(".jpg"):
# file name without extension
fileName = filenames.split(".")[0]
# slice file name by - to get last code name
codeName = int(fileName.split("-")[-1])
print(codeName)
# create new folder with codename
newFolder = mainFolder + "/" + str(codeName)
# create new folder if it doesn't exist
if not os.path.exists(newFolder):
os.makedirs(newFolder)
# move file to new folder
shutil.move(mainFolder + "/" + filenames, newFolder + "/" + filenames)


if __name__ == '__main__':
main()

0 comments on commit 492d6e3

Please sign in to comment.