趣学python3(48)--列出所有目录及子目录文件
生活随笔
收集整理的這篇文章主要介紹了
趣学python3(48)--列出所有目录及子目录文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
列出當前目錄及文件
from pathlib import Path srcPath = Path('../src/') [x for x in srcPath.iterdir() if srcPath.is_dir()]列出指定目錄及子目錄下的所有文件
from pathlib import Path srcPath = Path('../tensorflow-r1.11/') allFn=[] allPath=[srcPath,] i=1 while len(allPath)>0:nowPath=allPath.pop()pathInfo=[(x,x.is_dir()) for x in nowPath.iterdir() if nowPath.is_dir()]for fn,isPath in pathInfo:print("正在尋找:","<",str(i),">",fn)if not isPath:print("找到新文件:",fn)allFn.append(fn)else:print("找到新目錄:",fn)allPath.append(fn)i+=1print(nowPath,end="===>")print("尋找完畢") print("尋找完畢,共{}個目錄及文件".format(i))下面這種方式更簡潔
list(Path('../tensorflow-r1.11/').glob('/*') 與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的趣学python3(48)--列出所有目录及子目录文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 浅谈Normalize.css
- 下一篇: 趣学python3(46)--求素数