Isdir (‘ garbled name ‘) and ospath. Isfile (‘ garbled name ‘) are false.
Even if filename.decode(” GBK “).encode(” UTF-8 “) is sometimes used, problems still exist
# -*- coding: utf-8 -*-
import os
def listfiels(path):
path = path.replace("\ \"."/")
mlist = os.listdir(path)
for m in mlist:
mpath = os.path.join(path, m)
if os.path.isfile(mpath):
pt = os.path.abspath(mpath)
Encode ("utf-8") # print pt.decode(" GBK ").encode(" utF-8 ") #
print pt
else:
pt = os.path.abspath(mpath)
print pt
listfiels(pt)
listfiels(unicode("D:/test_temp/tmp_autonav/17Q2_A5_20170630/ROOT/ALL/WIDE_BACKGROUND"."utf-8"))
Copy the code
The emphasis is on using
unicode(path,”utf-8″)
Error: Python is reading a directory in Chinese