mbrofi.py 文件源码

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

项目:scripts 作者: mbfraga 项目源码 文件源码
def scan_files(self, recursive=True):
        """Scans the directory for files and populates the files list and 
        linebs. It is not a particularly fast implementation.

        Keyword arguments:
        recursive -- define whether scan should be recursive or not 
                     (default True)
        """
        self.__filecount = 0
        self.__files = []
        if recursive:
            for root, dirs, files in os.walk(self.__path, topdown=True):
                for name in files:
                    fp = os.path.join(root, name)
                    fp_rel = fp[self.__path_len:]

                    if (fp_rel[0] == '.'):
                        continue
                    try:
                        stat = os.stat(fp)
                    except:
                        continue

                    file_props = {}
                    file_props['size'] = stat[ST_SIZE]
                    file_props['adate'] = stat[ST_ATIME]
                    file_props['mdate'] = stat[ST_MTIME]
                    file_props['cdate'] = stat[ST_CTIME]
                    file_props['name'] = fp_rel
                    file_props['fullpath'] = fp
                    file_props['misc'] = None

                    self.__files.append(file_props)
                    self.__filecount += 1
        else:
            for f in os.scandir(self.__path):

                fp_rel = f.name
                fp = os.path.join(self.__path, fp_rel)
                if (fp_rel[0] == '.'):
                    continue
                if f.is_dir():
                    continue
                #try:
                #    stat = os.stat(fp)
                #except:
                #    continue

                file_props = {}
                file_props['size'] = f.stat()[ST_SIZE]
                file_props['adate'] = f.stat()[ST_ATIME]
                file_props['mdate'] = f.stat()[ST_MTIME]
                file_props['cdate'] = f.stat()[ST_CTIME]
                file_props['name'] = fp_rel
                file_props['fullpath'] = fp
                file_props['misc'] = None

                self.__files.append(file_props)
                self.__filecount += 1
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号