
1 revotu 2017-06-27 17:39:33 +08:00 Python 文件操作相关问题: http://www.revotu.com/python-file-operation-related-issues.html >>> import os >>> DIR = '/tmp' >>> print len([name for name in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, name))]) 如统计文件夹数量,用 os.path.isdir(path)做判断语句。 |
2 hemoely 2017-06-27 18:36:07 +08:00 用 python 套一个 shell |
3 yucongo 2017-06-28 00:40:47 +08:00 from pathlib import Path # Py3 自带 dir_path = '.' print(len(list(Path(dir_path).iterdir())) |