Skip to content

Instantly share code, notes, and snippets.

@ajmalanoski
Created April 15, 2021 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajmalanoski/6896859b9e9b57ad183e772a74135fae to your computer and use it in GitHub Desktop.
Save ajmalanoski/6896859b9e9b57ad183e772a74135fae to your computer and use it in GitHub Desktop.
Rename WikiPron files
#!/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