python 遍历文件夹读取文件名

来源:互联网 发布:云计算安全问题解决 编辑:程序博客网 时间:2024/05/16 04:13

遍历文件夹,读取某一特性的文件名

    def _dir(self, fpath, filetype):        if filetype == '**':            temp = '.**'        self.allfile = []        for parent, dirnames, filenames in os.walk(fpath):            for filename in filenames:                a = os.path.join(parent, filename)                if temp in a:                    self.allfile.append(a)        return self.allfile
  1. 从文件夹中批量获取文件名,并根据所给的条件删选出需要的文件名
  2. 将文件名保存在一个列表中

获取开头、结尾有特殊字符的文件名

if str(temp).startswith("") and str(temp).endswith("")    filename.append(temp)
原创粉丝点击