python——查詢linux指定目錄下所有的空目錄

來源:互聯網
上載者:User

標籤:return   AC   sys   std   site   roo   pytho   import   font   

 1 #!/usr/bin/env python3 2 # -*- coding: utf-8 -*- 3 #*******查詢指定目錄中的空目錄********* 4 #執行方法:python3 04-1.py + 目錄名稱 5 # a/b/c/f 6 # a/b/f 7 # a/b/r/1.txt 8 # python3 1.py a 9 #   --> a/b/c/f10 #       a/b/f11 import sys12 import os, os.path13 14 def find(p):15     fs = os.listdir(p)16     if len(fs) == 0:17         print(os.path.abspath(p))18         return19     for f in fs:20         pf = os.path.join(p, f)21         if not os.path.isdir(pf):22             continue23         find(pf)24 25 26 if __name__ == ‘__main__‘:27     find(sys.argv[1])

注意:執行的時候一定要加參數,否則會報錯
如:
[[email protected] 04-1-查詢指定目錄中的空目錄]# python3 04-1.py /root/
/root/python/Python-3.6.5/build/test_python_25442
/root/.local/lib/python3.6/site-packages
/root/.idlerc
/root/lpc/03/zero-檔案分類管理器/test/xyz/none
/root/lpc/04/04-1-查詢指定目錄中的空目錄/a/b/r/t/a/b/f
/root/lpc/04/04-1-查詢指定目錄中的空目錄/a/b/c/d/e/f
/root/lpc/04/04-1-查詢指定目錄中的空目錄/a/c/v/a/b
/root/lpc/04/04-1-查詢指定目錄中的空目錄/a/c/v/a/u/p


 

python——查詢linux指定目錄下所有的空目錄

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.