推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
donglongtu
V2EX  ›  Python

Python 统计某一文件夹下文件数量

  •  
  •   donglongtu · Jun 27, 2017 · 4967 views
    This topic created in 3241 days ago, the information mentioned may be changed or developed.
    有个文件夹 '/tmp',如何用 Python 统计其下文件数量?
    revotu
        1
    revotu  
       Jun 27, 2017   ❤️ 2
    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)做判断语句。
    hemoely
        2
    hemoely  
       Jun 27, 2017
    用 python 套一个 shell
    yucongo
        3
    yucongo  
       Jun 28, 2017
    from pathlib import Path # Py3 自带
    dir_path = '.'
    print(len(list(Path(dir_path).iterdir()))
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3345 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 12:54 · PVG 20:54 · LAX 05:54 · JFK 08:54
    ♥ Do have faith in what you're doing.