|
10鱼币
本帖最后由 欣欣celin 于 2014-8-9 23:16 编辑
- import os
- def countF(fPath):
- allFiles = os.listdir(os.curdir)
- #使用os.curdir表示当前目录更标准
- typeDict = dict()
- for eachFile in allFiles:
- if os.path.isdir(eachFile):#判断指定路径是否存在且是一个目录
- typeDict.setdefault(fPath, 0)
- typeDict[fPath] += 1
- else:
- ext = os.path.splitext(eachFile)[1]
- typeDict.setdefault(ext, 0)
- typeDict[ext] += 1
- for eachType in typeDict.keys():
- print('该文件夹下共有类型为[.%s]的文件%d个', % (eachType, typeDict[eachType]))
- fPath = str(input('请输入路径'))
- def countF(fPath)
复制代码 以上运行时报‘无效语法’,何解??
|
最佳答案
查看完整内容
这么改就对了 。。。
无视那个try 和 except PermissionError
因为有的文件需要权限打开,打不开就报错 用try 防止异常 你看到异常那课就知道了。。
|