推荐学习书目
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 29, 2017 · 6651 views
    This topic created in 3250 days ago, the information mentioned may be changed or developed.

    我用os.listdir(directory)==[]判断文件夹是否为空,然后再删除

    但是当 directory 下文件很多时,效率很低

    Python 怎样高效的删除空文件夹

    2 replies    2017-07-03 19:18:44 +08:00
    revotu
        1
    revotu  
       Jun 29, 2017
    Python 文件操作相关问题 :www.revotu.com/python-file-operation-related-issues.html

    ```Python
    try:
    os.rmdir(directory)
    except OSError:
    pass
    ```
    AX5N
        2
    AX5N  
       Jul 3, 2017
    os.rmdir()
    os.removedirs()
    大概能满足你的要求,不过你最好看一下官方文档对这 2 个函数的解释,否则出事了别找我
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2637 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 11:08 · PVG 19:08 · LAX 04:08 · JFK 07:08
    ♥ Do have faith in what you're doing.