|

楼主 |
发表于 2019-4-19 13:46:48
|
显示全部楼层
代码在这:- import os
- all_file = os.listdir(os.chdir('/home/Desktop/file'))
- count = 0
- num=0
- def replace(name, num):
- print('该文件夹下共有类型为[%s]的文件%d个'%(name, num))
- for each_file in all_file:
- if os.path.isdir(each_file):
- num = count(each_file)
- name='文件夹'
- replace(name, num)
- else:
- type = os.path.splitex(each_file)
- if type[1] =='txt':
- num = count(each_file)
- name = 'txt'
- replace(name, num)
- if type[1] == 'py':
- num = count(each_file)
- name='py'
- replace(name, num)
- if type[1] =='docx':
- num = count(each_file)
- name='docx'
- replace(name, num)
复制代码 |
|