Advertisement
Guest User

#1ZcjAJTP (Python)

a guest
Dec 15th, 2022
604
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. from pathlib import Path
  2. from opencc import OpenCC
  3.  
  4. # converter of simplified chinese to traditional chinese
  5. converter = OpenCC("s2t")
  6.  
  7. def convert_simplified_to_traditional(targetdir):
  8.     for file in targetdir.glob("*"):
  9.         if not file.is_dir():
  10.             continue
  11.         old_name = file.name
  12.         new_name = converter.convert(old_name)
  13.         if old_name == new_name:
  14.             continue
  15.         new_path = file.with_name(new_name)
  16.         file.rename(new_path)
  17.         print("Convert folder name from: {folder} to {new_path}")
  18.         # rename the subfolder
  19.         convert_simplified_to_traditional(new_path)
  20.  
  21. def main():
  22.     homedir = Path("D:\\Test")
  23.     convert_simplified_to_traditional(homedir)
  24.  
  25. if __name__ == "__main__":
  26.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement