-
-
Save ajmalanoski/6896859b9e9b57ad183e772a74135fae to your computer and use it in GitHub Desktop.
Rename WikiPron 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
#!/usr/bin/env python | |
"""Renames files. | |
This script changes filenames so that "phonemic" and "phonetic" are replaced | |
by "broad" and "narrow," respectively. | |
""" | |
import argparse | |
import os | |
def rename_files(directory: str) -> None: | |
os.chdir(directory) | |
for entry in os.listdir(): | |
if os.path.isdir(entry): | |
rename_files(entry) | |
elif "phonemic" in entry: | |
new_name = os.path.abspath(entry).replace("phonemic", "broad") | |
os.rename(entry, new_name) | |
elif "phonetic" in entry: | |
new_name = os.path.abspath(entry).replace("phonetic", "narrow") | |
os.rename(entry, new_name) | |
os.chdir("..") | |
def main() -> None: | |
rename_files(os.getcwd()) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment