Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Windows中处理UTF文件名_Python_Python 2.7_Filenames_Windows 7 X64_Utf - Fatal编程技术网

Python 在Windows中处理UTF文件名

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

给定以下文件:

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)
        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)   # <------