Skip to content

Instantly share code, notes, and snippets.

@ihfazhillah
Created June 24, 2017 06:17
Show Gist options
  • Save ihfazhillah/55c1848e218d14fffe068423077f408e to your computer and use it in GitHub Desktop.
Save ihfazhillah/55c1848e218d14fffe068423077f408e to your computer and use it in GitHub Desktop.
rename list of file to number
"""Suppose we have list of file like this
abcd-1.mp3
defg-2.mp3
in our folder. And we need to play all of these in sequence.
In my case, i will rename it to just an number like:
1.mp3
2.mp3
"""
import os
import re
# make sure, that you run this code in same folder with the audio files
for audio in os.listdir():
os.rename(audio, re.search("\d+", audio).group(0) + ".mp3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment