我正在嘗試找出如何在子目錄中列出檔案以回傳到我正在作業的目錄并繼續查找檔案
#!home/usr/env python3 import os files = [] pather = os.path while : for file in os.listdir(): if file == "for.py" or file.startswith("."): continue files.append(file) while os.path.isdir(file) == "True": os.chdir(file) if os.pathisfile(file): files.append(file)
列印(檔案)
到目前為止,這是我的代碼
如果你能請幫助那將是驚人的
uj5u.com熱心網友回復:
這應該有效:
import os
files = [os.path.join(path, name).replace(os.getcwd(), "") for path, subdirs, files in os.walk(os.getcwd()) for name in files]
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/480960.html
標籤:Python python-3.x 循环 目录 子目录
上一篇:如何遍歷串列中的每個元素并遞增一
下一篇:解構陣列陣列以訪問單個元素
