Created
July 26, 2022 12:25
-
-
Save ovuruska/b8008e90d1797850080d986a6597e2ff to your computer and use it in GitHub Desktop.
Rename files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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