返回列表 发帖

[原创代码] centos 8编码问题

centos 8 英文版下载带有中文字符的文件时,总是会乱码,比如10 ·ÖêÖÔúÄǸöÇïìì(¶Ô3a).MP3
写了一个py脚本来纠正文件名的编码问题,代码如下:
#!/usr/bin/env python3
import os,sys;
path=os.getcwd()
os.chdir(path)
files=os.listdir(path)
for f in files:
    if f.endswith(".mp3") or f.endswith(".MP3"):
        print(f)
        temp=f
        try:
            temp=temp.encode('ISO-8859-1')
        except UnicodeEncodeError:
            print('编码错误,继续下一个文件\n')
            continue
        temp=temp.decode('gb18030')
        print(temp,'已成功解码\n')
        os.rename(f,temp)            COPY

返回列表