1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > python 获取指定目录下的图片文件

python 获取指定目录下的图片文件

时间:2020-10-12 07:18:29

相关推荐

python 获取指定目录下的图片文件

import os#获取指定路径下所有的图片文件def listfile(dirpath):# pathdir = os.listdir(dirpath) #图片列表imgFileList = os.listdir(dirpath) #图片列表absPath = os.path.realpath(__file__) # 获取当前执行脚本的绝对路径dirPath = os.path.dirname(absPath) # 去掉文件名,返回目录for filename in imgFileList:filepath = os.path.join(dirpath, filename) #图片的绝对路径if os.path.isdir(filepath):listfile(filepath)print(filepath)else:if os.path.isfile(filepath) and filename.lower().endswith('.jpg'):print(os.path.join(dirPath, filename))dirpath=r'C:\Users\pic'listfile(dirpath)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。