Advertisement
ShawnHsia

資料夾繁簡轉換問題

Dec 15th, 2022
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | Help | 0 0
  1. from os import listdir, walk
  2. from os.path import join, isdir
  3. from opencc import OpenCC
  4. folderpath="D:\\Test"
  5.  
  6. for namelists2 in walk(folderpath):
  7.     for x in namelists2:
  8.         NameAndPath=join(folderpath, str(x))
  9.         if isdir(NameAndPath):
  10.             with open('allfolders.txt',mode='a+', encoding='utf-8') as list:
  11.                 cc=OpenCC('s2t')
  12.                 y=cc.convert(x)
  13.                 list.write(("os.rename(\"")+join(folderpath, x)+("\", ")+("\"")+join(folderpath, y)+"\""+")"+"\n" )
  14.                
  15.         else:
  16.             pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement