I've been facing following issue:
there is a directory, where online radio station is ripping and storing mp3 files
some if them is played and stored more times, difference is in the name : 1st file till dot has unique name : something.mp3 2nd file before dot has brackets : something(1).mp3 3rd file before dot has brackets : something(2).mp3 and so on.... I would like to delete the smaller files and only leave one of them. Therefor started following script :
#!/usr/bin/python3
import os import datetime import sys import glob from collections import Counter path = "/path_of_mp3_files/" dirs = os.listdir( path ) list_of_files = [] mp3files = [] mp3_with_bracket = [] mp3_without_bracket = [] pending_files = [] for file in dirs: if ")" not in file: mp3_without_bracket.append(file) else: mp3_with_bracket.append(file) print(mp3_with_bracket) print("-------------------------------------------------------------------------------------------------------------") print(mp3_without_bracket) mp3_without_bracket.sort() mp3_with_bracket.sort()
Logic behind is making 2 lists, with and without brackets. But what now? Could you give me some advice how to finish it? Anyway, is the logic good enough?