|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
课后练习第三十课的动手0,我按照小甲鱼的代码写了一遍,其他的文件类型都没有问题,但是这个文件夹为什么不显示?
http://bbs.fishc.com/thread-45649-1-2.html
- import os,os.path
- def file_dir(file_path):
- dict_file = {}
- all_file = os.listdir(file_path)
- for each_file in all_file:
- if os.path.isdir(each_file):
- dict_file.setdefault('文件夹',0)
- dict_file['文件夹'] += 1
- else:
- ext = os.path.splitext(each_file)[1]
- dict_file.setdefault(ext,0)
- dict_file[ext] += 1
- for ever in dict_file.keys():
- print('这个目录下的【%s】文件有 %d 个' %(ever,dict_file[ever]))
- print('----文件数量检查程序----')
- file_path = input('请输入要检查的目录:')
- file_dir(file_path)
复制代码
|
|