_files.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:QT4i 作者: Tencent 项目源码 文件源码
def force_delete(self, path=None):
        path = os.path.abspath(path or self.path)
        if path is None or os.path.exists(path) == False : return
        if os.path.isfile(path):
            os.chmod(path, stat.S_IWRITE)
            os.remove(path)
            return
        try    : shutil.rmtree(path)
        except :
            del_dir_paths = []
            for dirpath, dirnames, filenames in os.walk(path):
                try    : shutil.rmtree(dirpath)
                except :
                    del_dir_paths.append(dirpath)
                    for filename in filenames:
                        del_file_path = os.path.join(dirpath, filename)
                        os.chmod(del_file_path, stat.S_IWRITE)
                        os.remove(del_file_path)
            del_dir_paths.sort(reverse=True)
            for del_dir_path in del_dir_paths:
                os.chmod(del_dir_path, stat.S_IWRITE)
                os.rmdir(del_dir_path)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号