Skip to content

Instantly share code, notes, and snippets.

@ovuruska
Created July 26, 2022 12:25
Show Gist options
  • Save ovuruska/b8008e90d1797850080d986a6597e2ff to your computer and use it in GitHub Desktop.
Save ovuruska/b8008e90d1797850080d986a6597e2ff to your computer and use it in GitHub Desktop.
Rename files
import os
import re
if __name__ == "__main__":
root_dir = os.path.join("data", "audios")
os.chdir(root_dir)
files = os.listdir()
pattern = "(.*) \[.*\]\.[a-zA-Z0-9]*(\.wav)"
for file in files:
try:
new_filename = "".join(re.match(pattern,file).groups())
os.rename(file,new_filename)
except AttributeError:
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment