python shutil.rmtree 抛出错误 [英] python shutil.rmtree throwing errors

查看:83
本文介绍了python shutil.rmtree 抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给我解释一下为什么shutil.rmtree 会抛出错误,说目录不是空的?

Can someone explain to me why shutil.rmtree is throwning errors saying directory is not empty?

Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 810, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "W:\__init__.py", line 90, in makePatch
    myprog.copy_data()
  File "W:\myprog.py", line 143, in copy_data
    self.cleanupTempDir()
  File "W:\myprog.py", line 138, in cleanupTempDir
    shutil.rmtree(self.TEMP_DIR)
  File "C:\Python27\lib\shutil.py", line 247, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "C:\Python27\lib\shutil.py", line 256, in rmtree
    onerror(os.rmdir, path, sys.exc_info())
  File "C:\Python27\lib\shutil.py", line 254, in rmtree
    os.rmdir(path)
WindowsError: [Error 145] The directory is not empty: u'e:\\PatchData\\Data'

推荐答案

看起来文件被标记为只读.在复制文件后添加一行删除只读标志后,我不再收到此错误.奇怪的是,它看起来甚至没有尝试删除文件,或者至少没有对仅目录的文件引发任何异常.

Looks like the files were being marked as read-only. After adding a line to remove the read-only flag after the files are copied I am no longer getting this error. Strange that it would look like it is not even trying to remove the files or at least not raising any exceptions on the files only the directories.

这篇关于python shutil.rmtree 抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆