Skip to content

Instantly share code, notes, and snippets.

@SavinaRoja
Created August 29, 2018 14:14
Show Gist options
  • Save SavinaRoja/c1b739162b2dfbe45b0c5df529a32a2b to your computer and use it in GitHub Desktop.
Save SavinaRoja/c1b739162b2dfbe45b0c5df529a32a2b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
#Bandcamp filenames look like "<ARTIST> - <ALBUM> - ## TRACKNAME.flac"
old_names = [fn for fn in os.listdir('.') if os.path.splitext(fn)[1] == '.flac']
new_names = []
for name in old_names:
new_name = name.split(' - ', 2)[2]
int(new_name[:2]) # Will throw an error if this fails!
new_name = new_name[:2] + ' -' + new_name[2:]
new_names.append(new_name)
for old_name, new_name in zip(old_names, new_names):
os.rename(old_name, new_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment