|
本帖最后由 js66g 于 2024-6-16 00:52 编辑
场景:
1.文件夹下有1000个TXT文档;
2.找出GBK编码的文件;
方案:
- path_1 = r'F:\ZVZEE-9\txtv5\sd_all'
- filenames_1 = os.listdir(path_1)
- for filename_1 in filenames_1:
- file3=codecs.open(os.path.join(path_1,filename_1),'r','utf-8')
- try:
- html_doc=file3.read()
- except UnicodeDecodeError:
- print("UnicodeError..."+filename_1)
- file3.close()
- shutil.move(os.path.join(path_1,filename_1),os.path.join(path_2,filename_1))
复制代码
|
|