import os, eyed3, re, shutil path = input('Enter to full path to the directory containing you files: ') dest = input('Enter the full path to the destination: ') with os.scandir(path) as dir_entries: for entry in dir_entries: for entry in dir_entries: if bool(re.search(r'.*\.mp3', entry.name)) is True: file = eyed3.load(entry) artist = file.tag.artist artist = re.sub(r'(\/)|(\\)|(\:)|(\*)|(\?)|(\")|(\<)|(\>)|(\|)|(\ )$', ' ', artist) album = file.tag.album album = re.sub(r'(\/)|(\\)|(\:)|(\*)|(\?)|(\")|(\<)|(\>)|(\|)|(\ )$', ' ', album) artistIsExist = os.path.exists(f'{dest}\\{artist}') if not artistIsExist: os.makedirs(f'{dest}\\{artist}') albumIsExist = os.path.exists(f'{dest}\\{artist}\\{album}') if not albumIsExist: os.makedirs(f'{dest}\\{artist}\\{album}') song = entry.name song = re.sub(r'(\/)|(\\)|(\:)|(\*)|(\?)|(\")|(\<)|(\>)|(\-)|(\|)|(\ )$', '', song) song = re.sub(r'\ +', ' ', song) try: shutil.copy(entry.path, str(f'{dest}\\{artist}\\{album}\{song}')) except: print(song)