Skip to content

Instantly share code, notes, and snippets.

@AdamQuixote
Last active September 7, 2022 04:15
Show Gist options
  • Save AdamQuixote/cb924104fbe190cad3b9ca46dc025b9a to your computer and use it in GitHub Desktop.
Save AdamQuixote/cb924104fbe190cad3b9ca46dc025b9a to your computer and use it in GitHub Desktop.
Music archiver
"""
music-archiver
This script is used to archive music albums from a source directory to a flexible number of destination directories.
"""
import os, shutil
# make a list of folders to archive from the current directory
folders = [f for f in os.listdir() if os.path.isdir(f)]
# copy each folder to the two archive directories at D:\music\[genre]\ and I:\music\[genre]\, asking the user for a genre for each folder
for folder in folders:
# ignore __pycache__ and .git
if folder in ['__pycache__', '.git']:
continue
genre = input("Genre for " + folder + ": ")
if genre == "":
continue
for drive in ["D:\\music\\", "I:\\music\\"]:
if not os.path.exists(drive + genre):
os.mkdir(drive + genre)
try:
shutil.copytree(folder, drive + genre + "\\" + folder)
except FileExistsError:
print("Folder already exists in " + drive + genre + "\\" + folder)
continue
except PermissionError:
print("Permission denied for " + drive + genre + "\\" + folder)
continue
except:
print("Unknown error for " + drive + genre + "\\" + folder)
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment