python 获取指定目录下的图片文件
生活随笔
收集整理的這篇文章主要介紹了
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)
總結
以上是生活随笔為你收集整理的python 获取指定目录下的图片文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Python中的MySQL数据库编程
- 下一篇: Windows下查看端口被占用问题和解决