获取指定目录下所需要的文件

获取指定目录下所需要的文件
强烈推介IDEA2021.1.3破解激活,IntelliJ IDEA 注册码,2021.1.3IDEA 激活码  

大家好,我是架构君,一个会写代码吟诗的架构师。今天说一说获取指定目录下所需要的文件,希望能够帮助大家进步!!!

import glob
# 指定的目录地址
folder_path = '/home/w/Pictures/'
# pathname在这里填写匹配规则,我这里使用的匹配后缀的方式,匹配所有后缀是png的图片,"*"表示匹配任何字符
path_file_number=glob.glob(pathname='{}*.png'.format(folder_path))
print("返回所有符合条件的文件",path_file_number)
print("符合条件文件的数量",len(path_file_number))

运行结果

['/home/w/Pictures/Screenshot from 2021-01-07 15-50-55.png', '/home/w/Pictures/qqq.png', '/home/w/Pictures/Screenshot from 2021-06-24 11-00-58.png', '/home/w/Pictures/Screenshot from 2021-06-09 17-38-19.png', '/home/w/Pictures/Screenshot from 2021-06-08 09-22-44.png', '/home/w/Pictures/消息中间件.png', '/home/w/Pictures/Screenshot from 2021-06-29 15-27-13.png', '/home/w/Pictures/Screenshot from 2021-06-21 18-47-15.png', '/home/w/Pictures/意向锁.png', '/home/w/Pictures/Screenshot from 2021-06-24 16-03-03.png', '/home/w/Pictures/Screenshot from 2021-04-21 15-16-12.png', '/home/w/Pictures/009947.png']
12

Process finished with exit code 0
本文来源it小白求知路,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/29143

发表评论