Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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删除带有Unicode字符的文件_Python_Python 2.7_Unicode_Python Unicode - Fatal编程技术网

Python删除带有Unicode字符的文件

Python删除带有Unicode字符的文件,python,python-2.7,unicode,python-unicode,Python,Python 2.7,Unicode,Python Unicode,我正在用Python2编写一个清理方法,该方法应该删除所有文件,包括具有unicode名称的文件shutil.rmtree不是一个选项,因为它缺少我需要的控制 当时我尝试的是声明#-*-编码:utf-8-*-,然后使用.encode('utf-8')和.decode('utf-8')的组合,但没有成功。这就是我的方法在没有任何编码或解码的情况下的外观 def _remove_files(path): files = [] for dirpath, dirnames, filen

我正在用Python2编写一个清理方法,该方法应该删除所有文件,包括具有unicode名称的文件
shutil.rmtree
不是一个选项,因为它缺少我需要的控制

当时我尝试的是声明
#-*-编码:utf-8-*-
,然后使用
.encode('utf-8')
.decode('utf-8')
的组合,但没有成功。这就是我的方法在没有任何编码或解码的情况下的外观

def _remove_files(path):
    files = []

    for dirpath, dirnames, filenames in os.walk(path):
        for filename in [f for f in filenames]:
            files.append(os.path.join(dirpath, filename))

    for _file in files:
        print _file
        os.chmod(_file, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
        os.remove(_file)
这是我得到的错误:

WindowsError:[错误2]系统找不到指定的文件:u'C:\Users\xxxxx\yyyyy\\u65e5\u672c\u8a9e\u306e\u656c\u8a9e.txt'


这是给蟒蛇的吗?到底是什么不起作用?是否跳过unicode文件?我也有同样的问题。我在这里找到了对任何感兴趣的人都有用的指南。这是python2的指南吗?到底是什么不起作用?是否跳过unicode文件?我也有同样的问题。我在这里找到了对任何感兴趣的人都有用的指南。