您当前的位置: 首页 >  Python
  • 4浏览

    0关注

    157博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Python 获取文件夹下指定文件后缀数量

牙膏上的小苏打2333 发布时间:2022-07-13 10:37:17 ,浏览量:4

几个呀?

import os
from tkinter import filedialog

def GetDirFileCount(dirPath,suffix):
    count =0
    flist = os.listdir(dirPath)
    for i in flist:
        if os.path.splitext(i)[1] == '.{0}'.format(suffix):
            count +=1
    print('{0} 下格式为{1}的文件数量共有:{2}个'.format(dirPath,suffix,count))
    return count


foldPath = filedialog.askdirectory() # 获取选择的文件夹路径
GetDirFileCount(dirPath=foldPath,suffix='png')
关注
打赏
1664520285
查看更多评论
立即登录/注册

微信扫码登录

0.0821s