dotfiles/config/scripts/music_remove_dashes

33 lines
748 B
Plaintext
Raw Normal View History

2019-11-01 18:34:45 +01:00
#!/usr/bin/env python3
"""
Small script to convert music files in the form:
$(tracknumber) - $(title).$(ext)
to the form
$(tracknumber) $(title).$(ext)
(note the absence of dash)
"""
import os
import re
def main() -> None:
"""
Function that executes the script.
"""
for root, _, files in os.walk('.'):
for filename in files:
match = re.match(r'^(\d+) - (.+)$', filename)
if not match:
continue
new_filename = f"{match[1]} {match[2]}"
old_path = os.path.join(root, filename)
new_path = os.path.join(root, new_filename)
print(old_path, '->', new_path)
os.rename(old_path, new_path)
if __name__ == '__main__':
main()