win32_opts.py 文件源码

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

项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码
def isfile_cached(self):
        # optimize for nt.stat calls, assuming there are many files for few folders
        try:
            cache = self.__class__.cache_isfile_cache
        except AttributeError:
            cache = self.__class__.cache_isfile_cache = {}

        try:
            c1 = cache[id(self.parent)]
        except KeyError:
            c1 = cache[id(self.parent)] = []

            curpath = self.parent.abspath()
            findData = ctypes.wintypes.WIN32_FIND_DATAW()
            find     = FindFirstFile(TP % curpath, ctypes.byref(findData))

            if find == INVALID_HANDLE_VALUE:
                Logs.error("invalid win32 handle isfile_cached %r" % self.abspath())
                return os.path.isfile(self.abspath())

            try:
                while True:
                    if findData.cFileName not in UPPER_FOLDERS:
                        thatsadir = findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
                        if not thatsadir:
                            c1.append(str(findData.cFileName))
                    if not FindNextFile(find, ctypes.byref(findData)):
                        break
            except Exception as e:
                Logs.error('exception while listing a folder %r %r' % (self.abspath(), e))
                return os.path.isfile(self.abspath())
            finally:
                FindClose(find)
        return self.name in c1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号