Created
April 19, 2020 18:12
-
-
Save mikepietruszka/09c03bc1ea3f8a4a8959168f86618fee to your computer and use it in GitHub Desktop.
Simple movie sorter
This file contains hidden or 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
#!/usr/bin/env python | |
''' | |
Movie sorter | |
''' | |
import os | |
import shutil | |
import sys | |
path = sys.argv[1] | |
letters = [] | |
for dir in next(os.walk(path))[1]: | |
if dir.startswith("the ".lower()): | |
temp_dir = dir.split(" ") | |
first_char = temp_dir[1][0] | |
elif dir.startswith("the_".lower()): | |
temp_dir = dir.replace("_", " ").lower().split(" ") | |
first_char = temp_dir[1][0] | |
else: | |
first_char = dir[0] | |
if first_char not in letters: | |
letters.append(first_char) | |
new_dir_path = os.path.join(path, first_char.upper()) | |
if not os.path.exists(new_dir_path): | |
print("INFO: Making directory: {0}".format( | |
new_dir_path)) | |
os.mkdir(new_dir_path) | |
else: | |
new_dir_path = os.path.join(path, first_char.upper()) | |
print("Moving {0}{1} to {2}".format(path, dir, new_dir_path)) | |
try: | |
shutil.move(os.path.join(path, dir), new_dir_path) | |
except Exception as err: | |
print("ERROR: {0}".format(str(err))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment