Python 在Windows中处理UTF文件名
给定以下文件: E:/Media/Foo/info.nfo E:/Media/Bar/FXGâ¢.nfo 然后,此代码段将打印上述路径 但是,如果我确保由Python 在Windows中处理UTF文件名,python,python-2.7,filenames,windows-7-x64,utf,Python,Python 2.7,Filenames,Windows 7 X64,Utf,给定以下文件: E:/Media/Foo/info.nfo E:/Media/Bar/FXGâ¢.nfo 然后,此代码段将打印上述路径 但是,如果我确保由os.path.join()创建的每个路径确实是一个常规文件,例如: for dirpath, _, files in os.walk(BASE): for f in fnmatch.filter(files, '*.nfo'): nfopath = os.path.join(dirpath, f) pr
os.path.join()
创建的每个路径确实是一个常规文件,例如:
for dirpath, _, files in os.walk(BASE):
for f in fnmatch.filter(files, '*.nfo'):
nfopath = os.path.join(dirpath, f)
print(nfopath)
assert os.path.isfile(nfopath) # <------
对于os.walk(BASE)中的dirpath、\ux文件:
对于fnmatch.filter(文件'*.nfo')中的f:
nfopath=os.path.join(dirpath,f)
打印(路径)
assert os.path.isfile(nfopath)#根据,Windows在使用NTFS文件系统时将文件名存储为UTF-16。请使用UTF-16重试编码步骤。我不能肯定地告诉您,但是文件API在3.x中进行了修改,以便在windows中更好地处理unicode。你能试试3.x吗?试着打印repr(nfopath)
,看看这是否能帮你发光。
for dirpath, _, files in os.walk(BASE):
for f in fnmatch.filter(files, '*.nfo'):
nfopath = os.path.join(dirpath, f)
print(nfopath)
assert os.path.isfile(nfopath) # <------