利用Python编写一个程序 统计当前目录下的每个文件类型的文件数目

来源:互联网 发布:白芨吉利知胃病中草药 编辑:程序博客网 时间:2024/05/16 03:20

Python编写程序统计特定目录下的每个文件类型的文件数目




#第三十课作业 利用Python编写一个程序 统计当前目录下的每个文件类型的文件数目import os # os操作系统path = input("请输入您要统计的文件夹的绝对路径(当前目录下情输入#): ")if path == '#':        path ='.'files = os.listdir(path)#获得当前 硬盘目录中的所有文件count = dict()#存放每种文件数目的字典for i in files:#逐个文件遍历    if( os.path.isdir(i)):# 判断当前是一个文件夹'''        name = '文件夹'        if name in count:            count[name] +=1        else: count[name]=1    else :        name =os.path.splitext(i)[1]# 当前不是文件夹 获得当前的文件的扩展名        if name in count:            count[name]+=1        else :count[name]=1name = count.keys()for i in name:    print(i,'在当前目录中出现的次数为: ',count[i])'''http://bbs.fishc.com/forum.php?mod=viewthread&tid=45512&extra=page%3D1%26filter%3Dtypeid%26typeid%3D403'''






阅读全文
0 0
原创粉丝点击