I need to compare two folders on a XP machine.
This is a radio station, we have all our music stored as high bitrate mp3, when new songs are acquired from CD they are wav. I need to be able to compare the mp3 and the wav folders for duplicates (naming will be identical except for the file extension). The object is to produce a list of items in the wav folder that don't have mp3 versions.
Python 2.7 is installed and my very limited experience of coding has been with python.
All help appreciated, even if it is just a kick in the right direction... Thanks.
Use os.listdir to get the folder contents, and os.path.splitext to determine the base name:
import os
wavs = set(os.path.splitext(fn)[0] for fn in os.listdir('/path/to/wavs'))
mp3s = set(os.path.splitext(fn)[0] for fn in os.listdir('/path/to/mp3s'))
must_convert = wavs - mp3s
If you want to collate the mp3s and wavs of multiple folders (but not recursively), you'll have to store both basename and the full filename:
import os,collections
files = collections.defaultdict(dict)
for d in ['/path/to/wavs', '/more/wavs', '/some/mp3s', '/other/mp3s']:
for f in os.listdir(d):
basename,ext = os.path.splitext(f)
files[ext][basename] = os.path.join(d, f)
files_to_convert = [fn for basename,fn in files['.wav'].items()
if basename not in files['.mp3']]
import os
wav=[os.path.splitext(x)[0] for x in os.listdir(r'C:\Music\wav') if os.path.splitext(x)[1]=='.wav']
mp3=[os.path.splitext(x)[0] for x in os.listdir(r'C:\Music\mp3') if os.path.splitext(x)[1]=='.mp3']
#here wav is a list names of only those files whose extension is .wav
#here mp3 is a list names of only those files whose extension is .mp3
print(set(wav)-set(mp3))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With